Here you can find the source of dateToString(Date date, String format)
public static String dateToString(Date date, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String dateToString(Date date) { try {/*w w w . j ava 2s. c o m*/ if (date != null) return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); } catch (Exception e) { e.printStackTrace(); System.gc(); } return null; } public static String dateToString(Date date, String format) { try { if (date != null) return new SimpleDateFormat(format).format(date); } catch (Exception e) { e.printStackTrace(); System.gc(); } return null; } }