Here you can find the source of formatDateTime(long time)
public static String formatDateTime(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> simpleTimeFormatThreadLocal = new ThreadLocal<SimpleDateFormat>() { @Override//from w ww . j a v a2 s . c o m protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); } }; 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(); } 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()); } }