Android examples for java.util:Millisecond
get current time in milliseconds, format is #DEFAULT_DATE_FORMAT
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static final SimpleDateFormat DATETIME_FORMAT_DATE = new SimpleDateFormat( "yyyy-MM-dd kk:mm:ss"); /**// www . java2 s . c om * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT} * * @return */ public static String getCurrentTimeInString() { return getTime(getCurrentTimeInLong()); } /** * get current time in milliseconds * * @return */ public static String getCurrentTimeInString(SimpleDateFormat dateFormat) { return getTime(getCurrentTimeInLong(), dateFormat); } /** * long time to string * * @param timeInMillis * @param dateFormat * @return */ public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) { return dateFormat.format(new Date(timeInMillis)); } /** * long time to string, format is {@link #DEFAULT_DATE_FORMAT} * * @param timeInMillis * @return */ public static String getTime(long timeInMillis) { return getTime(timeInMillis, DATETIME_FORMAT_DATE); } /** * get current time in milliseconds * * @return */ public static long getCurrentTimeInLong() { return System.currentTimeMillis(); } }