Here you can find the source of getStrDateByFormat(Date time, String format)
public static String getStrDateByFormat(Date time, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String getStrDateByFormat(Date time, String format) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); if (time == null) { return ""; }/*from w w w. j ava 2 s .c o m*/ if (format == null || format.equals("")) { return dateFormat.format(time); } else { SimpleDateFormat f = new SimpleDateFormat(format); return f.format(time); } } }