Here you can find the source of format(Date date)
public static String format(Date date)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String format(Date date, String format) { if (date == null || format == null) { return ""; }//from w w w . ja v a2 s .co m DateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } public static String format(Date date) { return format(date, "yyyy-MM-dd HH:mm"); } public static String format(Date date, boolean isDateOnly) { if (isDateOnly) { return date(date); } else { return format(date); } } public static String date(Date date) { return format(date, "yyyy-MM-dd"); } }