Here you can find the source of formatDate(Date date, String format)
public static String formatDate(Date date, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.*; public class Main { public static String formatDate(Date date, String format) { if (format == null || "".equals(format)) { format = "yyyy-MM-dd HH:mm:ss"; }/*from w w w. j av a2s. c o m*/ SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } public static String formatDate(long timestamp, String format) { if (format == null || "".equals(format)) { format = "yyyy-MM-dd HH:mm:ss"; } SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(new Date(timestamp)); } }