List of utility methods to do Milliseconds
int | millisecondsSinceMidnight(Date date) milliseconds Since Midnight Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("GMT")); cal.setTime(date); return cal.get(Calendar.HOUR_OF_DAY) * 3600000 + cal.get(Calendar.MINUTE) * 60000 + cal.get(Calendar.SECOND) * 1000 + cal.get(Calendar.MILLISECOND); |
Date | millisToDate(String stime) millis To Date long time = Long.parseLong(stime); return new Date(time); |
String | minutusAndSecondsFromMillis(long millis) minutus And Seconds From Millis return String.format("%d min, %d sec", millis2minutes(millis), millis2seconds(millis) - minutes2seconds(millis2minutes(millis))); |
String | msToString(long milliseconds) ms To String long sec = milliseconds / 1000; long min = sec / 60; long hour = min / 60; milliseconds %= 1000; sec %= 60; min %= 60; DecimalFormat twoDigits = new DecimalFormat("00"); return new String(twoDigits.format(hour) + ":" + twoDigits.format(min) + ":" + twoDigits.format(sec) + "." ... |
long | multiplyRelativeTimeMillis(long duration, long multiplier) Multiplies a duration in relative milliseconds by a multiplier while accounting for overflow and underflow of the magnitude value. if (multiplier < 0) { throw new IllegalArgumentException("Only non-negative multipliers are allowed."); long result_mag = (Long.MIN_VALUE != duration) ? Long.highestOneBit(Math.abs(duration)) + Long.highestOneBit(multiplier) : Long.SIZE + Long.highestOneBit(multiplier); long result = duration * multiplier; if (result_mag > (Long.SIZE - 1)) { ... |
String | nowMillis() now Millis SimpleDateFormat formater = new SimpleDateFormat("yyyyMMddHHmmssSSS"); Date d = new Date(); return formater.format(d); |
long | OLEDateToMillis(double dSerialDate) OLE Date To Millis return (long) ((dSerialDate - 25569) * 24 * 3600 * 1000); |
Date | parseDate(long milliseconds) parse Date return new Date(milliseconds); |
String | printTimeFromMilliseconds(long milliseconds) print Time From Milliseconds if ((milliseconds > 1000) && (milliseconds < 60000)) { return (milliseconds / 1000) + "s"; if (milliseconds > 60000) { return (milliseconds / 60000) + "min " + printTimeFromMilliseconds(milliseconds % 60000); return milliseconds + "ms"; |
void | putMillisToByteArray(byte[] buff, long value, int offset) Stores a long milliseconds as seconds in a byte array. value /= 1000L; buff[offset + 0] = (byte) (value & 0xff); buff[offset + 1] = (byte) ((value & 0xff00) >>> 8); buff[offset + 2] = (byte) ((value & 0xff0000) >>> 16); buff[offset + 3] = (byte) ((value & 0xff000000) >>> 24); |