List of utility methods to do Milliseconds
String | readableTransferRate(long size, long millis) readable Transfer Rate double rate = size / ((double) millis); long rateInt = Math.round(rate) * 1000l; return readableFileSize(rateInt); |
String | relTimestrMillis(long time) rel Timestr Millis long h = time / 3600000; long m = ((time / 1000) % 3600) / 60; long s = (((time / 1000) % 3600) % 60); long ss = time % 1000; return leadZero(h, 2) + "h:" + leadZero(m, 2) + "m:" + leadZero(s, 2) + "," + leadZero(ss, 3) + "s"; |
Date | resetHourMinSecMill(final Date date) Reset hours, minutes, seconds and milliseconds final int hourOfDay = 17; final Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); ... |
long | resetMilliseconds(long msec) reset Milliseconds int offset = (int) (msec % 1000); if (offset < 0) { offset += 1000; return msec - offset; |
long | reverseTimeMillis(long currentTimeMillis) reverse Time Millis return Long.MAX_VALUE - currentTimeMillis;
|
Date | rollMockClockMillis(long millis) Advances (or rewinds) the mock clock by the given number of milliseconds. if (mockTime == null) throw new IllegalStateException("You need to use setMockClock() first."); mockTime = new Date(mockTime.getTime() + millis); return mockTime; |
int | roundMicrosToMillis(String micros) round Micros To Millis assert micros != null && micros.length() == 4; double dblMicros = Integer.valueOf(micros).doubleValue(); return (int) Math.round(dblMicros / 10.0); |
long | roundMillisWithSecondPrecision(long l) round Millis With Second Precision return Math.round(((double) l) / 1000) * 1000; |
long | roundTimeToTheNearestSecondInMilliseconds(long timeInMilliseconds) Round time in Milliseconds to the nearest second, and return as time in milliseconds double timeInSeconds = ((double) timeInMilliseconds) / 1000.0; timeInSeconds = Math.round(timeInSeconds); long roundedTimeInMilliseconds = (long) (timeInSeconds * 1000.0); return roundedTimeInMilliseconds; |
void | safeSleepMillis(long milliseconds) Sleep for specified number of milliseconds without having to bother catching the InterruptedException potentially thrown by the regular sleep method. try { Thread.sleep(milliseconds); } catch (InterruptedException e) { e.printStackTrace(); |