Class TimeKit
java.lang.Object
com.iohao.net.common.kit.time.TimeKit
Time utilities providing cached or real-time date/time access.
- Since:
- 25.1
- Author:
- 渔民小镇
- date:
- 2025-09-09
-
Method Summary
Modifier and TypeMethodDescriptionstatic longGet the current nano time, cached if caching is enabled.static longget currentTimeMillisstatic longelapsedMicros(long nanoTime) Calculate elapsed microseconds since the given nano time.static longelapsedMillis(long nanoTime) Calculate elapsed milliseconds since the given nano time.static voidEnable time caching to reduce object creation at the cost of precision.static booleanexpireLocalDate(long epochDay) Check if the given epoch day has expired compared to the current date.static booleanexpireLocalDate(LocalDate localDate) Check if the given LocalDate has expired compared to the current date.static booleanexpireMillis(long milli) Check if the given timestamp in milliseconds has expired.static ZoneIdstatic LocalDateget LocalDatestatic LocalDateTimeget LocalDateTimestatic LocalTimeget LocalTimestatic voidsetDefaultZoneId(ZoneId defaultZoneId) static longtoEpochMilli(LocalDateTime localDateTime) Convert a LocalDateTime to epoch milliseconds using the default zone.static LocalDateTimetoLocalDateTime(long millis) Convert epoch milliseconds to a LocalDateTime using the default zone.
-
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
-
nowLocalDateTime
-
nowLocalTime
-
toEpochMilli
Convert a LocalDateTime to epoch milliseconds using the default zone.- Parameters:
localDateTime- the local date/time to convert- Returns:
- the epoch milliseconds
-
toLocalDateTime
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:
trueif the date has expired
-
expireLocalDate
Check if the given LocalDate has expired compared to the current date.- Parameters:
localDate- the date to check- Returns:
trueif 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:
trueif the timestamp has expired
-
getDefaultZoneId
-
setDefaultZoneId
-