Here you can find the source of dateToString(java.util.Date currdate, String strFormat)
public static final String dateToString(java.util.Date currdate, String strFormat)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static String defaultDatePattern = "yyyy-MM-dd"; public static final String dateToString(java.util.Date currdate, String strFormat) { String returnDate = ""; try {/* w w w. j ava 2 s.c o m*/ SimpleDateFormat sdf = new SimpleDateFormat(strFormat); if (currdate == null) return returnDate; else returnDate = sdf.format(currdate); } catch (NullPointerException e) { } return returnDate; } public static String format(Date date) { return date == null ? "" : format(date, getDatePattern()); } public static String format(Date date, String pattern) { return date == null ? "" : new SimpleDateFormat(pattern).format(date); } public static String getDatePattern() { return defaultDatePattern; } }