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.SimpleDateFormat; import java.util.Date; public class Main { private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); public static String formatDate() { return ((SimpleDateFormat) sdf.clone()).format(new Date()); }/*from www . j a v a 2 s .c o m*/ public static String formatDate(Date date) { return date != null ? ((SimpleDateFormat) sdf.clone()).format(date) : null; } public static String formatDate(Date date, String format) { return date != null && format != null ? new SimpleDateFormat(format).format(date) : null; } }