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: LGPL import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static String format(Date date, String pattern) { String result = null;//from www . j a v a2s. c om result = ""; if (date != null) { SimpleDateFormat formatter = new SimpleDateFormat(); formatter.applyPattern(pattern); result = formatter.format(date); } return result; } public static String format(Date date, String pattern, String locale) { String result = null; result = ""; if (date != null) { Locale _locale = null; try { _locale = new Locale(locale); } catch (Throwable t) { _locale = null; } SimpleDateFormat formatter = (_locale != null ? new SimpleDateFormat(pattern, _locale) : new SimpleDateFormat(pattern)); //formatter.applyPattern(pattern); result = formatter.format(date); } return result; } }