Here you can find the source of yyyyMMdd(Date date)
public static String yyyyMMdd(Date date)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.Map; public class Main { private static final String a = "yyyy-MM-dd HH:mm:ss:SSS"; private static final String b = "yyyyMMdd"; private static final String e = "yyyy-MM-dd HH:mm:ss"; private static final ThreadLocal<Map<String, SimpleDateFormat>> threadLocal = new ThreadLocal<Map<String, SimpleDateFormat>>(); public static String yyyyMMdd() { return getDateFormat(b).format(new Date()); }/*from www . j a va 2s . co m*/ public static String yyyyMMdd(long now) { return getDateFormat(b).format(new Date(now)); } public static String yyyyMMdd(Date date) { return getDateFormat(b).format(date); } public static String format() { return getDateFormat(a).format(new Date()); } public static String format(String s) { return getDateFormat(s).format(new Date()); } public static String format(Calendar calendar) { return getDateFormat(a).format(calendar.getTime()); } public static String format(Calendar calendar, String s) { return getDateFormat(s).format(calendar.getTime()); } public static String format(Date date) { return getDateFormat(e).format(date); } public static String format(Date date, String s) { return getDateFormat(s).format(date); } private static SimpleDateFormat getDateFormat(String format) { Map<String, SimpleDateFormat> map = threadLocal.get(); if (map == null) { map = new HashMap<String, SimpleDateFormat>(); threadLocal.set(map); } SimpleDateFormat f = map.get(format); if (f == null) { f = new SimpleDateFormat(format); map.put(format, f); } return f; } }