我需要将标准的长 System.currentmillis 转换为临时访问器,但不知道如何开始。
最佳答案
Instant
是一个 TemporalAccessor
,因此您可以从纪元以来的毫秒数创建一个 Instant
:
TemporalAccessor ta = Instant.ofEpochMilli(System.currentTimeMillis());
请注意 System.currentTimeMillis
的文档表示该值的粒度取决于操作系统,因此可能不是以毫秒为单位的精确时间。
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.
关于java - 如何将 System.currentMillis 秒转换为 TemporalAccessor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55559376/