Here you can find the source of getStringFromTime(Date time, String format)
public static String getStringFromTime(Date time, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public final static String FORMAT_DATE_TIME = "yyyy-MM-dd hh:mm"; private static SimpleDateFormat sdf = new SimpleDateFormat(); public static String getStringFromTime(Date time, String format) { if (format == null || format.trim().equals("")) { sdf.applyPattern(FORMAT_DATE_TIME); } else {/*from w w w . jav a 2 s . co m*/ sdf.applyPattern(format); } return sdf.format(time); } }