Class Timestring
java.lang.Object
tech.guilhermekaua.spigotboot.core.utils.Timestring
A utility class for parsing duration strings into numeric values.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Timestring
public Timestring()
-
-
Method Details
-
duration
Convert a duration string to the specified time unit.Examples:
duration("5m 30s", "s")returns330.0duration("1h30m", "m")returns90.0duration("2.5d", "h")returns60.0duration("1e3ms", "s")returns1.0
- Parameters:
str- the string to parse (e.g., "5m 30s", "1h30m", "2.5d")format- the unit to return the result in (e.g., "s", "ms", "h"). If null, returns milliseconds.- Returns:
- the parsed value in the specified format, or -1 if parsing fails
-
durationLong
Convert a duration string to the specified time unit as a long.- Parameters:
str- the string to parseformat- the unit to return the result in- Returns:
- the parsed value in the specified format, or -1 if parsing fails
-