Class TimeKit

java.lang.Object
com.iohao.net.common.kit.time.TimeKit

public final class TimeKit extends Object
Time utilities providing cached or real-time date/time access.
Since:
25.1
Author:
渔民小镇
date:
2025-09-09
  • Method Details

    • enableCache

      public static void enableCache()
      Enable time caching to reduce object creation at the cost of precision.
    • currentTimeMillis

      public static long currentTimeMillis()
      get currentTimeMillis
      Returns:
      System.currentTimeMillis()
    • currentNanoTime

      public static long currentNanoTime()
      Get the current nano time, cached if caching is enabled.
      Returns:
      the current nano time
    • nowLocalDate

      public static LocalDate nowLocalDate()
      get LocalDate
      Returns:
      LocalDate
    • nowLocalDateTime

      public static LocalDateTime nowLocalDateTime()
      get LocalDateTime
      Returns:
      LocalDateTime
    • nowLocalTime

      public static LocalTime nowLocalTime()
      get LocalTime
      Returns:
      LocalTime
    • toEpochMilli

      public static long toEpochMilli(LocalDateTime localDateTime)
      Convert a LocalDateTime to epoch milliseconds using the default zone.
      Parameters:
      localDateTime - the local date/time to convert
      Returns:
      the epoch milliseconds
    • toLocalDateTime

      public static LocalDateTime toLocalDateTime(long millis)
      Convert epoch milliseconds to a LocalDateTime using the default zone.
      Parameters:
      millis - the epoch milliseconds
      Returns:
      the corresponding LocalDateTime
    • elapsedMillis

      public static long elapsedMillis(long nanoTime)
      Calculate elapsed milliseconds since the given nano time.
      Parameters:
      nanoTime - the starting nano time
      Returns:
      the elapsed time in milliseconds
    • elapsedMicros

      public static long elapsedMicros(long nanoTime)
      Calculate elapsed microseconds since the given nano time.
      Parameters:
      nanoTime - the starting nano time
      Returns:
      the elapsed time in microseconds
    • expireLocalDate

      public static boolean expireLocalDate(long epochDay)
      Check if the given epoch day has expired compared to the current date.
      Parameters:
      epochDay - the epoch day to check
      Returns:
      true if the date has expired
    • expireLocalDate

      public static boolean expireLocalDate(LocalDate localDate)
      Check if the given LocalDate has expired compared to the current date.
      Parameters:
      localDate - the date to check
      Returns:
      true if the date has expired
    • expireMillis

      public static boolean expireMillis(long milli)
      Check if the given timestamp in milliseconds has expired.
      Parameters:
      milli - the timestamp in milliseconds to check
      Returns:
      true if the timestamp has expired
    • getDefaultZoneId

      public static ZoneId getDefaultZoneId()
    • setDefaultZoneId

      public static void setDefaultZoneId(ZoneId defaultZoneId)