Package tk.airshipcraft.commonlib.utils
Class Time
java.lang.Object
tk.airshipcraft.commonlib.utils.Time
Provides utility methods for working with time values in Java.
This includes methods for getting the current time in various formats
and converting between different units of time.
- Since:
- 2023-04-02
- Version:
- 1.0.0
- Author:
- notzune
-
Method Summary
Modifier and TypeMethodDescriptionstatic Duration
Calculates the absolute duration between the current time and another specified instant.static Duration
static Instant
now()
Retrieves the current time as anInstant
.static long
Retrieves the current Unix time in milliseconds.static long
Retrieves the current Unix time in seconds.
-
Method Details
-
nowMillis
public static long nowMillis()Retrieves the current Unix time in milliseconds.- Returns:
- The current Unix time in milliseconds since the epoch.
-
nowSeconds
public static long nowSeconds()Retrieves the current Unix time in seconds.- Returns:
- The current Unix time in seconds since the epoch.
-
now
Retrieves the current time as anInstant
.- Returns:
- The current time as an
Instant
.
-
diffToNow
Calculates the absolute duration between the current time and another specified instant. -
duration
- Parameters:
unit
- TheTimeUnit
representing the unit of the duration.amount
- The amount of the specified unit.- Returns:
- A
Duration
representing the specified amount of the specified time unit. - Throws:
NullPointerException
- if the specified unit is null.AssertionError
- if the time unit is unknown or unsupported.
-