List of utility methods to do Milliseconds
long | getPeriodDurationInMillis(int period) get Period Duration In Millis return periodDurations[period];
|
long | GetTimeInMilliseconds(Date date) Get Time In Milliseconds Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.getTimeInMillis() + cal.getTimeZone().getOffset(cal.getTimeInMillis());
|
String | getTimeStringFromMilliseconds(long millis) get Time String From Milliseconds int sec = (int) ((millis / 1000L) % 60L); int min = (int) (millis / 60000L); return ((min < 10) ? " " : "") + Integer.toString(min) + ':' + ((sec < 10) ? "0" : "") + Integer.toString(sec); |
long | getTimeZoneOffSetInMillisecond(String dateString) get Time Zone Off Set In Millisecond String timeZoneOffSetInHour = getTimeZoneOffSetInHour(dateString); if (timeZoneOffSetInHour.length() == 5) { String flag = timeZoneOffSetInHour.substring(0, 1); Integer hour = Integer.parseInt(timeZoneOffSetInHour.substring(1, 3)); Integer minute = Integer.parseInt(timeZoneOffSetInHour.substring(3, 5)); if (DATE_SEPARATOR_MINUS.equals(flag)) { hour = -hour; minute = -minute; ... |
long | getUnitLengthMillis(String unit) Gets the length of the given unit in milliseconds. unit = unit.trim(); if (unit.equals("seconds") || unit.equals("second") || unit.equals("secs") || unit.equals("sec") || unit.equals("s")) { return 1000; } else if (unit.equals("minutes") || unit.equals("minute") || unit.equals("mins") || unit.equals("min")) { return 1000 * 60; } else if (unit.equals("hours") || unit.equals("hour") || unit.equals("hrs") || unit.equals("hr") || unit.equals("h")) { ... |
boolean | hasExpiredMillis(long now, long eventTime, long timeBuffer) Test whether a given event has timed out (in milliseconds). return (eventTime + timeBuffer) < now;
|
long | hhmmssToMillis(String text) hhmmss To Millis if (text.matches("^\\d\\d:\\d\\d:\\d\\d$")) { int hours = Integer.parseInt(text.substring(0, 2)); int minutes = Integer.parseInt(text.substring(3, 5)); int seconds = Integer.parseInt(text.substring(6, 8)); return (((hours * 60L + minutes) * 60L) + seconds) * 1000L; return -1; |
long | humanDateToMillisecondsWithoutException(String date) human Date To Milliseconds Without Exception try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS"); sdf.setTimeZone(CURRENT_TIME_ZONE); Date d = sdf.parse(date); return d.getTime(); } catch (ParseException ex) { return 0L; |
boolean | isSameSecondOfMillis(final long ms1, final long ms2) is Same Second Of Millis final long interval = ms1 - ms2; return interval < 1000L && interval > -1000L && (ms1 / 1000L == ms2 / 1000L); |
String | longToDate(long millis) Turns a long variable that represents time into a String Date date = new Date(millis); SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); dateFormat.setTimeZone(TimeZone.getDefault().getTimeZone("GMT")); return dateFormat.format(date); |