Android examples for java.util:Date Format
Convert time in milliseconds to string with format yyyy-MM-dd HH:mm:ss.
import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main{ /**/* www . ja v a2 s. c o m*/ * Convert time in milliseconds to string with format yyyy-MM-dd HH:mm:ss. * * @param milis Milliseconds * * @return String of time */ public static String timeMilisToString(long milis) { SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milis); return sd.format(calendar.getTime()); } /** * Convert time in milliseconds to string with format yyyy-MM-dd HH:mm:ss. * * @param milis Milliseconds * * @return String of time */ public static String timeMilisToString(long milis, String format) { SimpleDateFormat sd = new SimpleDateFormat(format); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(milis); return sd.format(calendar.getTime()); } }