Here you can find the source of formatDate(final Date date)
public static String formatDate(final Date date)
//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 w ww .j av a 2 s . co 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); } }