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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongGet the current nano time, cached if caching is enabled.longget currentTimeMillislongelapsedMicros(long nanoTime) Calculate elapsed microseconds since the given nano time.longelapsedMillis(long nanoTime) Calculate elapsed milliseconds since the given nano time.voidEnable time caching to reduce object creation at the cost of precision.booleanexpireLocalDate(long epochDay) Check if the given epoch day has expired compared to the current date.booleanexpireLocalDate(LocalDate localDate) Check if the given LocalDate has expired compared to the current date.booleanexpireMillis(long milli) Check if the given timestamp in milliseconds has expired.get LocalDateget LocalDateTimeget LocalTimelongtoEpochMilli(LocalDateTime localDateTime) Convert a LocalDateTime to epoch milliseconds using the default zone.toLocalDateTime(long millis) Convert epoch milliseconds to a LocalDateTime using the default zone.
-
Constructor Details
-
TimeKit
public TimeKit()
-
-
Method Details
-
enableCache
public void enableCache()Enable time caching to reduce object creation at the cost of precision. -
currentTimeMillis
public long currentTimeMillis()get currentTimeMillis- Returns:
- System.currentTimeMillis()
-
currentNanoTime
public 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 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 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 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 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
-