Here you can find the source of format(final long timeInMillis)
Parameter | Description |
---|---|
timeInMillis | a parameter |
public static final String format(final long timeInMillis)
//package com.java2s; //License from project: Open Source License import java.text.SimpleDateFormat; import java.util.Date; public class Main { private static final SimpleDateFormat SIMPLE_DATE_MINUTE_SECONDS_FORMAT = new SimpleDateFormat("mm:ss"); private static final SimpleDateFormat SIMPLE_DATE_SECONDS_FORMAT = new SimpleDateFormat("ss"); private static final long NUMBER_OF_MILLISECONDS_LESS_THAN_MINUTE = 59999; /**//from www.jav a 2s .co m * Formats milliseconds into a {@link String} date representation of:</br> * solely seconds when less than 59999 or minutes and seconds when more. * @param timeInMillis * @return date representation */ public static final String format(final long timeInMillis) { return (isLessThanMinute(timeInMillis) ? SIMPLE_DATE_SECONDS_FORMAT : SIMPLE_DATE_MINUTE_SECONDS_FORMAT) .format(new Date(timeInMillis)); } /** * Checks if a number of milliseconds is less than a minute or not. * @param timeInMillis * @return <code>true</code> when less than a minute, otherwise <code>false</code> */ public static final boolean isLessThanMinute(final long timeInMillis) { return timeInMillis >= 0 && timeInMillis < NUMBER_OF_MILLISECONDS_LESS_THAN_MINUTE; } }