Here you can find the source of format(Date date, String pattern)
public static String format(Date date, String pattern)
//package com.java2s; //License from project: Open Source License import java.sql.Timestamp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static final Map<String, DateFormat> DFS = new HashMap<String, DateFormat>(); public static String format(Date date, String pattern) { if (date == null) { return null; }/* w w w. j a va 2 s . c o m*/ return getFormat(pattern).format(date); } public static String format(Timestamp tt, String pattern) { if (tt == null) { return null; } Date date = new Date(tt.getTime()); return getFormat(pattern).format(date); } public static DateFormat getFormat(String pattern) { DateFormat format = DFS.get(pattern); if (format == null) { format = new SimpleDateFormat(pattern); DFS.put(pattern, format); } return format; } }