public class TimeUtils extends Object
Constructor and Description |
---|
TimeUtils() |
Modifier and Type | Method and Description |
---|---|
static String |
formatWithHighestUnit(java.time.Duration duration)
Pretty prints the duration as a lowest granularity unit that does not lose precision.
|
static String |
getStringInMillis(java.time.Duration duration) |
static java.time.Duration |
parseDuration(long number,
String unitLabel)
Parse the given number and unitLabel to a java
Duration . |
static java.time.Duration |
parseDuration(String text)
Parse the given string to a java
Duration . |
public static java.time.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 java.time.Duration parseDuration(long number, String unitLabel)
Duration
. The usage is in format
"(digital number, time unit label)", e.g. "(1, DAYS)".number
- a digital numberunitLabel
- time unit labelpublic static String getStringInMillis(java.time.Duration duration)
duration
- to convert to stringpublic static String formatWithHighestUnit(java.time.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.Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.