Here you can find the source of date2String(java.util.Date date, String format)
public static String date2String(java.util.Date date, String format)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; public class Main { private static String defaultFormat = "yyyy-MM-dd"; public static String date2String(java.util.Date date, String format) { if (date == null) { return null; }//from w w w.ja va2s . co m if (format == null || "".equals(format)) { format = defaultFormat; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); String dateOfStr = ""; try { dateOfStr = simpleDateFormat.format(date); } catch (Exception e) { e.printStackTrace(); } return dateOfStr; } }