Here you can find the source of formatDate(Date date)
public static String formatDate(Date date)
//package com.java2s; //License from project: Apache License import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static SimpleDateFormat dateSdf = new SimpleDateFormat("yyyyMMdd"); public static String formatDate(Date date) { return dateSdf.format(date); }//from ww w. j a v a 2s . c om public static String formatDate(String date) { return dateSdf.format(parseDate(date)); } public static Date parseDate(String date) { try { return dateSdf.parse(date); } catch (ParseException e) { e.printStackTrace(); } return null; } }