Java Utililty Methods Milliseconds

List of utility methods to do Milliseconds

Description

The list of methods to do Milliseconds are organized into topic(s).

Method

doublecyclesToMillis(long cycles, double hz)
cycles To Millis
return 1000 * ((double) cycles) / hz;
StringdateToMillis(Date date)
Formats a Date as a fifteen character long String made up of the Date's padded millisecond value.
return zeroPadString(Long.toString(date.getTime()), 15);
StringdateToMillis(Date date)
Formats a Date as a fifteen character long String made up of the Date's padded millisecond value.
return zeroPadString(Long.toString(date.getTime()), 15);
StringdateToMillis(long now)
save the datetime of System.currentTimeMillis() to dtatbase persistence.
return zeroPadString(Long.toString(now), 15);
intdayValue2Millisecond(int dayValue)
1 day = 1*24*60*60*1000 millisecond.
return (dayValue * 24 * 60 * 60 * 1000);
int[]decomposeMillis(long millis)
Decompose millis into 0:days, 1:hours, 2:minutes, 3:seconds, 4:millis.
final int[] result = new int[5];
result[4] = (int) (millis % 1000);
long seconds = (millis / 1000);
if (seconds == 0)
    return result;
result[3] = (int) (seconds % 60);
long minutes = (seconds / 60);
if (minutes == 0)
...
voiddelayUntilNextSecond(int millis)
delay Until Next Second
long now = System.currentTimeMillis();
Calendar cal = Calendar.getInstance();
cal.setTime(new Date(now));
cal.set(Calendar.MILLISECOND, millis);
cal.add(Calendar.SECOND, 1);
long next = cal.getTime().getTime();
try {
    Thread.sleep(next - now);
...
longdiffInMillis(long instantOne, long instantTwo)
Diff is for instant, does not consider time zone
return instantTwo - instantOne;
longdiffMillisec(String lhs, String rhs)
diff Millisec
synchronized (DATE_FORMAT) {
    Date l = DATE_FORMAT.parse(lhs);
    Date r = DATE_FORMAT.parse(rhs);
    return l.getTime() - r.getTime();
longdiffTimeInMillis(long start, long end)
diff Time In Millis
return end - start;