| Modifier and Type | Method and Description |
|---|---|
static double |
convert(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit)
Converts the given duration and time unit into another time unit, as double, with no
rounding.
|
static double |
convertAndRound(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit)
Converts the given duration to a different time unit, with double-precision;
For example, to convert 10 minutes to milliseconds, use:
TimeUnitConverter.convertAndRound(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)
Note: The number of decimal places applied is determined by calling
ConfigurationHolder.getConfiguration().getScale()
|
static double |
convertAndRound(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit,
int decimalPlaces)
Converts the given duration to a different time unit, with double-precision and a
custom number of decimal places.
|
public static double convertAndRound(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit)
Converts the given duration to a different time unit, with double-precision;
For example, to convert 10 minutes to milliseconds, use:
TimeUnitConverter.convertAndRound(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)
Note: The number of decimal places applied is determined by calling
ConfigurationHolder.getConfiguration().getScale()
sourceDuration - the time duration to be convertedsourceTimeUnit - the unit of the sourceDuration argumenttargetTimeUnit - the target time unitpublic static double convertAndRound(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit,
int decimalPlaces)
Converts the given duration to a different time unit, with double-precision and a custom number of decimal places.
For example, to convert 999 milliseconds to seconds, with a precision of 2 decimal
places, use:
TimeUnitConverter.convertAndRound(999, TimeUnit.MILLISECONDS, TimeUnit.SECONDS, 2)
Remarks:
decimalPlaces is greater than zero, the number is rounded to the
specified number of decimal placesdecimalPlaces is zero, the number is rounded to the nearest integerdecimalPlaces is less than zero, the number is rounded to the left of
the decimal point
Examples:
convertAndRound(988, TimeUnit.MILLISECONDS, TimeUnit.SECONDS, 2) = 0.99 convertAndRound(988, TimeUnit.MILLISECONDS, TimeUnit.SECONDS, 0) = 1
sourceDuration - the time duration to be convertedsourceTimeUnit - the unit of the sourceDuration argumenttargetTimeUnit - the target time unittargetTimeUnit - the target time unitdecimalPlaces - the number of decimal places to which the number will be roundedpublic static double convert(long sourceDuration,
TimeUnit sourceTimeUnit,
TimeUnit targetTimeUnit)
Converts the given duration and time unit into another time unit, as double, with no rounding.
For example, to convert 10 minutes to milliseconds, use:
TimeUnitConverter.convert(10, TimeUnit.MINUTES, TimeUnit.MILLISECONDS)
sourceDuration - the time duration to be convertedsourceTimeUnit - the unit of the sourceDuration argumenttargetTimeUnit - the target time unitCopyright © 2020. All rights reserved.