Here you can find the source of formatDate(final Date date, String pattern)
public static String formatDate(final Date date, String pattern)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DEFAULT_PATTERN = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_PATTERN = "yyyy-MM-dd"; /**//from ww w.j a va 2 s .c o m * format date by given pattern */ public static String formatDate(final Date date, String pattern) { if (date == null) { return null; } if (pattern == null) { pattern = DEFAULT_PATTERN; } final SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } public static String formatDate(final Date date) { if (null == date) { return ""; } final SimpleDateFormat formatter = new SimpleDateFormat(DATE_PATTERN); return formatter.format(date); } }