Here you can find the source of date2String(Date date)
public static String date2String(Date date)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.*; public class Main { private static SimpleDateFormat sdfDash = new SimpleDateFormat("MM-dd-yyyy"); private static SimpleDateFormat sdfSlash = new SimpleDateFormat("MM/dd/yyyy"); private static SimpleDateFormat sdfColon = new SimpleDateFormat("MM:dd:yyyy"); public static String date2String(Date date) { return date2String(date, "-"); }/*ww w. j av a 2 s.c o m*/ public static String date2String(Date date, String delimiter) { if (date == null) return null; if (sdfDash == null) sdfDash = new SimpleDateFormat("MM-dd-yyyy"); if (sdfSlash == null) sdfSlash = new SimpleDateFormat("MM/dd/yyyy"); if (sdfColon == null) sdfColon = new SimpleDateFormat("MM:dd:yyyy"); if (delimiter == null) { return sdfDash.format(date); } else if (delimiter.trim().equals("-")) { return sdfDash.format(date); } else if (delimiter.trim().equals("/")) { return sdfSlash.format(date); } else if (delimiter.trim().equals(":")) { return sdfColon.format(date); } else { return sdfDash.format(date); } } }