Class Time

java.lang.Object
tk.airshipcraft.commonlib.utils.Time

public final class Time extends Object
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 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

      public static Instant now()
      Retrieves the current time as an Instant.
      Returns:
      The current time as an Instant.
    • diffToNow

      public static Duration diffToNow(Instant other)
      Calculates the absolute duration between the current time and another specified instant.
      Parameters:
      other - The Instant to compare with the current time.
      Returns:
      The absolute Duration between now and the provided instant.
    • duration

      public static Duration duration(TimeUnit unit, long amount)
      Creates a Duration based on a specified TimeUnit and amount.
      Parameters:
      unit - The TimeUnit 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.