Here you can find the source of formatDate2String(Date date, String format)
public static final String formatDate2String(Date date, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static final String formatDate2String(Date date, String format) { if (isNull(date)) return null; SimpleDateFormat sdf = new SimpleDateFormat(format); String dateString = ""; try {/*w ww. j av a 2 s. c om*/ dateString = sdf.format(date); } catch (Exception e) { //logger.error(e.getMessage()); } return dateString; } public static final String formatDate2String(Date date, String format, Locale locale) { if (isNull(date)) return null; SimpleDateFormat sdf = new SimpleDateFormat(format, locale); String dateString = ""; try { dateString = sdf.format(date); } catch (Exception e) { //logger.error(e.getMessage()); } return dateString; } public static final boolean isNull(Object str) { return (str == null || str.toString().trim().length() == 0); } }