Here you can find the source of getDateFormat(Date date, String format)
public static String getDateFormat(Date date, String format)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**/* w w w . j a va 2 s.c o m*/ * @author Administrator * format = "yyyy-MM-dd" * format = "yyyy-MM-dd HH:mm:ss" */ public static String getDateFormat(Date date, String format) { String strDateTime = ""; DateFormat df = new SimpleDateFormat(format); Calendar cal = Calendar.getInstance(); cal.setTime(date); strDateTime = df.format(date); return strDateTime; } }