Here you can find the source of formatDate(Date date, String format)
public static String formatDate(Date date, String format)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static DateFormat datefmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static String formatDate(Date date, String format) { if (date == null) return null; String str_date = null;/* w ww. ja v a2 s . com*/ if (format != null) { DateFormat formater = new SimpleDateFormat(format); str_date = formater.format(date); } else { str_date = datefmt.format(date); } return str_date; } }