Java Utililty Methods TimeUnit Usage

List of utility methods to do TimeUnit Usage

Description

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

Method

longgetSecondsDateDiff(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);
intgetSecondsTimeStamp()
get Seconds Time Stamp
return (int) TimeUnit.NANOSECONDS.toSeconds(System.nanoTime());
longgetTime()
get Time
return TimeUnit.MILLISECONDS.toSeconds(new Date().getTime());
longgetTimeComparisonEpsilonMicros()
get Time Comparison Epsilon Micros
return timeComparisonEpsilonMicros;
StringgetTimeDifference(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)
...
StringgetTimeFormat(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;
DategetTimeForS3URL()
Makes time for S3 URL access
return new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1));
longgetTimeInMillis(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;
...
StringgetTimeString(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);
...
StringgetTimezoneOffset(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());
...