Here you can find the source of formatDate(long time)
public static String formatDate(long time)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; public class Main { private static ThreadLocal<SimpleDateFormat> simpleDateFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() { @Override//from w ww . ja v a 2 s. c o m protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd"); } }; private static ThreadLocal<SimpleDateFormat> simpleTimeFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); } }; public static String formatDate(long time) { SimpleDateFormat format = getDateFormat(); Calendar calendar = getCalendar(time); return format.format(calendar.getTime()); } public static SimpleDateFormat getDateFormat() { return simpleDateFormatThreadLocal.get(); } public static Calendar getCalendar() { return Calendar.getInstance(TimeZone.getTimeZone("UTC")); } public static Calendar getCalendar(long time) { Calendar calendar = getCalendar(); calendar.setTimeInMillis(time); return calendar; } public static String format(long time, SimpleDateFormat format) { if (format == null) { return formatDateTime(time); } Calendar calendar = getCalendar(time); return format.format(calendar.getTime()); } public static String formatDateTime(long time) { SimpleDateFormat format = getTimeFormat(); Calendar calendar = getCalendar(time); return format.format(calendar.getTime()); } public static SimpleDateFormat getTimeFormat() { return simpleTimeFormatThreadLocal.get(); } }