Here you can find the source of formatDateByFormat(Date date, String format)
public static String formatDateByFormat(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 { public static String formatDateByFormat(Date date, String format) { String result = ""; if (date != null) { try { SimpleDateFormat sdf = new SimpleDateFormat(format); result = sdf.format(date); } catch (Exception ex) { ex.printStackTrace();/*from w w w . java2 s . co m*/ } } return result; } public static String format(Date date, String format) { String result = ""; try { if (date != null) { DateFormat dateFormat = new SimpleDateFormat(format); result = dateFormat.format(date); } } catch (Exception localException) { } return result; } public static String format(Date date) { return format(date, "yyyy-MM-dd"); } }