Android examples for java.util:Date Convert
Form System.currentTimeMillis(), in milliseconds In format "yyyy-MM-dd HH:mm:ss"
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { private static SimpleDateFormat sDateTimeFormat = null; private static SimpleDateFormat getDefaultFormatInstance() { if (sDateTimeFormat == null) { sDateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); }//from w w w .j a va2s. c o m return sDateTimeFormat; } /** * @param time * returned by System.currentTimeMillis(), in milliseconds. * @return In format "yyyy-MM-dd HH:mm:ss" */ public static String formatDateTime(long time) { return getDefaultFormatInstance().format(new Date(time)); } }