Here you can find the source of dateToString(Date pdttValue, String pstrDateFormat)
public static String dateToString(Date pdttValue, String pstrDateFormat)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Date; public class Main { /**/*from w w w .ja va2 s .co m*/ * yyyy-MM-dd */ public static final String DATE_FORMAT = "yyyy-MM-dd"; public static String dateToString(Date pdttValue) { return dateToString(pdttValue, null); } /** * Date convert to String. * * @return String representation of the given Date and DateFormat. */ public static String dateToString(Date pdttValue, String pstrDateFormat) { String pstrDate = null; // return value if (pdttValue == null || "".equals(pdttValue)) { return null; } String formatStyle = null; if ((pstrDateFormat == null) || (pstrDateFormat.equals(""))) { formatStyle = DATE_FORMAT; } else { formatStyle = pstrDateFormat; } SimpleDateFormat oFormatter = new SimpleDateFormat(formatStyle); pstrDate = oFormatter.format(pdttValue); return pstrDate; } }