Java Utililty Methods TimeUnit Convert

List of utility methods to do TimeUnit Convert

Description

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

Method

doubleconvert(double t, TimeUnit sourceUnit, TimeUnit destinationUnit)
convert
switch (sourceUnit) {
case NANOSECONDS:
    return nanosToUnit(t, destinationUnit);
case MICROSECONDS:
    return microsToUnit(t, destinationUnit);
case MILLISECONDS:
    return millisToUnit(t, destinationUnit);
case SECONDS:
...
longconvert(long time, TimeUnit src, TimeUnit dst)
Converts the given time and TimeUnit to an another TimeUnit .
return dst.convert(time, src);
doubleconvert(long time, TimeUnit unitIn, TimeUnit unitOut)
convert
return (double) unitIn.toNanos(time) / (double) unitOut.toNanos(1);
longconvert(TimeUnit unitTo, TimeUnit unitFrom, long cnt)
convert
return unitTo.convert(unitFrom.toMillis(cnt), TimeUnit.MILLISECONDS);
longconvertReportingPeriod(long profilePeriod, TimeUnit profileTimeUnit, long reportingPeriod, TimeUnit reportingTimeUnit)
Convert a reporting period into the time scale of a profiling period
long convertedReportingPeriod = profileTimeUnit.convert(reportingPeriod, reportingTimeUnit);
if (convertedReportingPeriod <= profilePeriod) {
    return 1;
return convertedReportingPeriod / profilePeriod;
longconvertTo(long a, TimeUnit from, TimeUnit to)
convert To
switch (to) {
case NANOSECONDS:
    return from.toNanos(a);
case MICROSECONDS:
    return from.toMicros(a);
case MILLISECONDS:
    return from.toMillis(a);
case SECONDS:
...
doubleconvertToDouble(long fromTime, TimeUnit fromTimeUnit, TimeUnit toTimeUnit)
convert To Double
return (fromTimeUnit.ordinal() >= toTimeUnit.ordinal())
        ? (double) toTimeUnit.convert(fromTime, fromTimeUnit)
        : ((double) fromTime) / fromTimeUnit.convert(1, toTimeUnit);
longconvertToMillis(long waitTime, TimeUnit timeUnit)
convert To Millis
return timeUnit.toMillis(waitTime);
longconvertToMilliseconds(TimeUnit timeUnit, long seed)
convert To Milliseconds
switch (timeUnit) {
case MILLISECONDS:
    return seed;
case SECONDS:
    return fromSeconds(seed);
case MINUTES:
    return fromMinutes(seed);
case HOURS:
...
intconvertToSecond(int interval, TimeUnit unit)
convert To Second
switch (unit) {
case DAYS:
    return interval * DateTimeConstants.SECONDS_PER_DAY;
case HOURS:
    return interval * DateTimeConstants.SECONDS_PER_HOUR;
case MINUTES:
    return interval * DateTimeConstants.SECONDS_PER_MINUTE;
case SECONDS:
...