List of utility methods to do Millisecond Format
long | millisOf(long timestamp) millis Of return timestamp / 10000;
|
int | millisPerBeat(final float bpm) Given a beats-per-minute rate, returns the number of milliseconds in a single beat. return (int) (60000f / bpm); |
long | millisSince(long from) millis Since long until = System.currentTimeMillis(); return until - from; |
String | millisToDate(long millis, String format) millis To Date return new SimpleDateFormat(format).format(new Date(millis)); |
long | millisTrimTo(long millis, long unitInMillis) millis Trim To long remains = millis % unitInMillis; return millis - remains; |
String | parseDate(long millisec, String format) parse Date try { SimpleDateFormat formatter = new SimpleDateFormat(format); Date formattedDate = new Date(millisec); String result = formatter.format(formattedDate); return result; } catch (Exception e) { e.printStackTrace(); return null; |
String | prettyPrintMillis(long millis) Prints a time for display return prettyPrintTime(millis, TimeUnit.MILLISECONDS);
|
String | prettyPrintMillis(long millis) Prints a time for display if (millis < 1000) return millis + " milliseconds"; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); double toPrint = ((double) millis) / 1000; if (toPrint < 300) { return nf.format(toPrint) + " seconds"; toPrint = toPrint / 60; if (toPrint < 120) { return nf.format(toPrint) + " minutes"; toPrint = toPrint / 60; return nf.format(toPrint) + " hours"; |
String | prettyPrintTime(long millis) Prints a time for display if (millis < 1000) return millis + " milliseconds"; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMaximumFractionDigits(2); double toPrint = ((double) millis) / 1000; if (toPrint < 300) { return nf.format(toPrint) + " seconds"; toPrint = toPrint / 60; if (toPrint < 120) { return nf.format(toPrint) + " minutes"; toPrint = toPrint / 60; return nf.format(toPrint) + " hours"; |
String | printDate(long millis) print Date return DATE_FORMAT.format(new Date(millis)); |