Java tutorial
//package com.java2s; import java.text.DecimalFormat; import java.util.Calendar; public class Main { public static String getFormatTime4(long time) { Calendar c = Calendar.getInstance(); c.setTimeInMillis(time); String strFileName = getFormatTime1(c); return strFileName; } /** * yyyy-MM-dd HH:mm:ss */ public static String getFormatTime1(Calendar c) { if (null == c) { return "null"; } DecimalFormat df = new DecimalFormat("00"); String strCurrTime = c.get(Calendar.YEAR) + "-" + df.format((c.get(Calendar.MONTH) + 1)) + "-" + df.format(c.get(Calendar.DAY_OF_MONTH)) + " " + df.format(c.get(Calendar.HOUR_OF_DAY)) + ":" + df.format(c.get(Calendar.MINUTE)) + ":" + df.format(c.get(Calendar.SECOND)); return strCurrTime; } }