Here you can find the source of format(Date date)
public static String format(Date date)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss"; private static SimpleDateFormat sdf = new SimpleDateFormat(DEFAULT_PATTERN); public static String format(Date date) { if (date == null) { throw new NullPointerException(); }/*from w w w. ja va 2 s .co m*/ sdf = new SimpleDateFormat(DEFAULT_PATTERN); return sdf.format(date); } public static String format(Date date, String pattern) { if (date == null) { throw new NullPointerException(); } if (pattern != null) { sdf = new SimpleDateFormat(pattern); } return sdf.format(date); } }