public class TimeUtils extends Object
Constructor and Description |
---|
TimeUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
formatWithHighestUnit(Duration duration)
Pretty prints the duration as a lowest granularity unit that does not lose precision.
|
static String |
getStringInMillis(Duration duration) |
static Duration |
parseDuration(String text)
Parse the given string to a java
Duration . |
static Duration |
toDuration(Time time)
Deprecated.
Use
Duration APIs |
public static Duration parseDuration(String text)
Duration
. The string is in format "{length
value}{time unit label}", e.g. "123ms", "321 s". If no time unit label is specified, it will
be considered as milliseconds.
Supported time unit labels are:
text
- string to parse.public static String getStringInMillis(Duration duration)
duration
- to convert to stringpublic static String formatWithHighestUnit(Duration duration)
Examples:
Duration.ofMilliseconds(60000) will be printed as 1 min
Duration.ofHours(1).plusSeconds(1) will be printed as 3601 s
NOTE: It supports only durations that fit into long.@Deprecated public static Duration toDuration(Time time)
Duration
APIstime
- time to transform into durationCopyright © 2014–2024 The Apache Software Foundation. All rights reserved.