Here you can find the source of formatDate(Date src, String formatPattern)
public static String formatDate(Date src, String formatPattern)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String formatDate(Date src, String formatPattern) { if (src == null) { return ""; }/*from w w w . j ava 2 s . c om*/ DateFormat fmt = new SimpleDateFormat(formatPattern); return fmt.format(src); } public static String formatDate(Date src) { return formatDate(src, "yyyy-MM-dd HH:mm:ss"); } public static String formatDate() { return formatDate(new Date(), "yyyy-MM-dd"); } public static String formatDate(String formatPattern) { return formatDate(new Date(), formatPattern); } }