List of utility methods to do TimeUnit Usage
long | getSecondsDateDiff(Date dateStart) get Seconds Date Diff Calendar cal = Calendar.getInstance(); Date dateEnd = cal.getTime(); long diffInMillies = dateEnd.getTime() - dateStart.getTime(); TimeUnit timeUnit = TimeUnit.SECONDS; return timeUnit.convert(diffInMillies, TimeUnit.MILLISECONDS); |
int | getSecondsTimeStamp() get Seconds Time Stamp return (int) TimeUnit.NANOSECONDS.toSeconds(System.nanoTime()); |
long | getTime() get Time return TimeUnit.MILLISECONDS.toSeconds(new Date().getTime()); |
long | getTimeComparisonEpsilonMicros() get Time Comparison Epsilon Micros return timeComparisonEpsilonMicros;
|
String | getTimeDifference(Date startDate, Date endDate) get Time Difference String result = ""; long duration = endDate.getTime() - startDate.getTime(); long diffInMilli = TimeUnit.MILLISECONDS.toMillis(duration); long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration); long diffInMinutes = TimeUnit.MILLISECONDS.toMinutes(duration); long diffInHours = TimeUnit.MILLISECONDS.toHours(duration); long diffInDays = TimeUnit.MILLISECONDS.toDays(duration); if (diffInDays > 0) ... |
String | getTimeFormat(final long time) get Time Format final String format = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) % TimeUnit.HOURS.toMinutes(1), TimeUnit.MILLISECONDS.toSeconds(time) % TimeUnit.MINUTES.toSeconds(1)); return time < 3600000 ? format.substring(3) : format; |
Date | getTimeForS3URL() Makes time for S3 URL access return new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)); |
long | getTimeInMillis(String str) Interprets a string specifying a time duration. TimeUnit timeUnit; int unitsLen = 1; switch (str.charAt(str.length() - 1)) { case 'd': timeUnit = TimeUnit.DAYS; break; case 'h': timeUnit = TimeUnit.HOURS; ... |
String | getTimeString(long millis) Formats milliseconds into human readable text. if (millis < 1L) { return "not very long!"; } else { long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); ... |
String | getTimezoneOffset(TimeZone timeZone) get Timezone Offset long hours = TimeUnit.MILLISECONDS.toHours(timeZone.getRawOffset()); long minutes = TimeUnit.MILLISECONDS.toMinutes(timeZone.getRawOffset()) - TimeUnit.HOURS.toMinutes(hours); minutes = Math.abs(minutes); String result = ""; if (hours > 0) { result = String.format("GMT+%d:%02d %s", hours, minutes, timeZone.getID()); } else { result = String.format("GMT%d:%02d %s", hours, minutes, timeZone.getID()); ... |