Here you can find the source of date2Str(Date date)
public static String date2Str(Date date)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.*; public class Main { public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); public static SimpleDateFormat customerFormat = new SimpleDateFormat("yyyyMMdd"); public static String date2Str(Date date) { try {/*from www .j a v a 2s . c o m*/ return dateFormat.format(date); } catch (Exception ex) { return ""; } } public static String date2Str(Date date, String pattern) { try { customerFormat.applyPattern(pattern); return customerFormat.format(date); } catch (Exception ex) { return ""; } } }