public class ThreadNow extends Object
Provides thread-level customization of the clock. The default implementation uses ThreadLocal and does not support inheritable. The default ThreadLocal can be replaced by subclassing `init`, e.g. using TransmittableThreadLocal. Note that (1) To avoid ThreadLocal leakage, it is recommended to use try-finally mode. (2) subclass replacement must before any use, such as Spring's container configuration before the business. Benchmark Mode Cnt Score Error Units Now.localDateTime(CN) thrpt 6 11554.389 ± 1750.603 ops/ms LocalDateTime.now(CN) thrpt 6 13434.876 ± 686.115 ops/ms ThreadNow.sysZone() thrpt 6 19666.947 ± 4895.100 ops/ms ZoneId.systemDefault() thrpt 6 263911.747 ± 13128.798 ops/ms
| Modifier and Type | Field and Description |
|---|---|
static TweakingContext<Clock> |
TweakClock |
static TweakingContext<TimeZone> |
TweakZone |
static TimeZone |
UtcTimeZone |
static ZoneId |
UtcZoneId |
| Constructor and Description |
|---|
ThreadNow() |
| Modifier and Type | Method and Description |
|---|---|
static @NotNull Clock |
clock()
get current clock
|
static @NotNull Clock |
clock(ZoneId zid) |
static @NotNull Instant |
instant() |
static @NotNull Instant |
instant(ZoneId zid) |
static @NotNull LocalDate |
localDate() |
static @NotNull LocalDate |
localDate(ZoneId zid) |
static @NotNull LocalDateTime |
localDateTime() |
static @NotNull LocalDateTime |
localDateTime(ZoneId zid) |
static @NotNull LocalTime |
localTime() |
static @NotNull LocalTime |
localTime(ZoneId zid) |
static long |
millis()
get current millis
|
static @NotNull OffsetDateTime |
offsetDateTime() |
static @NotNull OffsetDateTime |
offsetDateTime(ZoneId zid) |
static TimeZone |
sysTimeZone()
get system timezone
|
static ZoneId |
sysZoneId()
get system zoneid, Java11 is optimized
|
static TimeZone |
utcTimeZone()
get UTC timezone
|
static ZoneId |
utcZoneId()
get UTC zoneid
|
static @NotNull Date |
utilDate() |
static @NotNull Date |
utilDate(ZoneId zid) |
static @NotNull ZonedDateTime |
zonedDateTime() |
static @NotNull ZonedDateTime |
zonedDateTime(ZoneId zid) |
public static final TimeZone UtcTimeZone
public static final ZoneId UtcZoneId
public static final TweakingContext<TimeZone> TweakZone
public static final TweakingContext<Clock> TweakClock
public static TimeZone sysTimeZone()
public static ZoneId sysZoneId()
public static TimeZone utcTimeZone()
UtcTimeZone@NotNull public static @NotNull Clock clock()
public static long millis()
@NotNull public static @NotNull Instant instant()
@NotNull public static @NotNull LocalDate localDate()
@NotNull public static @NotNull LocalTime localTime()
@NotNull public static @NotNull LocalDateTime localDateTime()
@NotNull public static @NotNull ZonedDateTime zonedDateTime()
@NotNull public static @NotNull OffsetDateTime offsetDateTime()
@NotNull public static @NotNull Date utilDate()
@NotNull public static @NotNull LocalDateTime localDateTime(ZoneId zid)
@NotNull public static @NotNull ZonedDateTime zonedDateTime(ZoneId zid)
@NotNull public static @NotNull OffsetDateTime offsetDateTime(ZoneId zid)
Copyright © 2024. All rights reserved.