如何将 System.currentMillisSeconds 转换为 TemporalAccessor
How to convert System.currentMillisSeconds to a TemporalAccessor
我需要将标准的 long System.currentmillis 转换为临时访问器,但不知道如何开始。
Instant
是一个 TemporalAccessor
,因此您可以从纪元以来的毫秒数创建一个 Instant
:
TemporalAccessor ta = Instant.ofEpochMilli(System.currentTimeMillis());
请注意 System.currentTimeMillis
的文档说值的粒度取决于 OS,因此它可能不是以毫秒为单位的精确时间。
Returns the current time in milliseconds. Note that while the unit of
time of the return value is a millisecond, the granularity of the
value depends on the underlying operating system and may be larger.
For example, many operating systems measure time in units of tens of
milliseconds.
我需要将标准的 long System.currentmillis 转换为临时访问器,但不知道如何开始。
Instant
是一个 TemporalAccessor
,因此您可以从纪元以来的毫秒数创建一个 Instant
:
TemporalAccessor ta = Instant.ofEpochMilli(System.currentTimeMillis());
请注意 System.currentTimeMillis
的文档说值的粒度取决于 OS,因此它可能不是以毫秒为单位的精确时间。
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.