Here you can find the source of date2Str(Date date, String pattern)
public static String date2Str(Date date, String pattern)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; public static String date2Str(Date date, String pattern) { if (null == date) { return null; }/*from w w w. ja v a 2 s.c o m*/ if (null == pattern) { pattern = DEFAULT_DATE_FORMAT; } SimpleDateFormat format = new SimpleDateFormat(); format.applyPattern(pattern); return format.format(date); } }