Here you can find the source of format(long time, SimpleDateFormat format)
public static String format(long time, SimpleDateFormat format)
//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> simpleTimeFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() { @Override/* w ww . j a va 2 s .c om*/ protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); } }; 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 Calendar getCalendar() { return Calendar.getInstance(TimeZone.getTimeZone("UTC")); } public static Calendar getCalendar(long time) { Calendar calendar = getCalendar(); calendar.setTimeInMillis(time); return calendar; } public static SimpleDateFormat getTimeFormat() { return simpleTimeFormatThreadLocal.get(); } }