Here you can find the source of getDateOfString(long time, String patten)
public static String getDateOfString(long time, String patten) throws ParseException
//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); } }