Java SQL Date Get getDateOfString(long time, String patten)

Here you can find the source of getDateOfString(long time, String patten)

Description

get Date Of String

License

Open Source License

Declaration

public static String getDateOfString(long time, String patten) throws ParseException 

Method Source Code


//package com.java2s;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.Locale;

public class Main {
    public static String getDateOfString(long time, String patten) throws ParseException {
        if (time != 0) {
            return (new SimpleDateFormat(patten).format(new Date(time))).toString();
        }/* w  w  w . jav a  2  s . c  o  m*/
        return "";
    }

    public static String getDateOfString(Timestamp time, String patten) throws ParseException {
        if (time != null) {
            return (new SimpleDateFormat(patten).format(new Date(time.getTime()))).toString();
        }
        return "";
    }

    public static String format(Date d, String format) {
        return format(d, format, Locale.getDefault());
    }

    public static String format(Date d, String format, Locale locale) {
        if (d == null)
            return "";
        DateFormat df = new SimpleDateFormat(format, locale);
        return df.format(d);
    }
}

Related

  1. getDateFromYMD(Date ymd)
  2. getDateInput(String prompt)
  3. getDateISO(final String sDate)
  4. getDateNextMonth(java.util.Date current)
  5. getDateOfShortStr(String dateStr)
  6. getDateOrTime(int colType, Object o)
  7. getDateParameter(java.sql.Date date, int param)
  8. getDatePath(java.sql.Timestamp fileDate)
  9. getDatePath(java.util.Date fileDate)