java - 如何将 System.currentMillis 秒转换为 TemporalAccessor

标签 java milliseconds temporal

我需要将标准的长 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/

相关文章:

Java win32 库/api

java - 您可以使用 Gradle 有条件地准备任务吗?

javascript - 使用 JavaScript 将两个时间参数相加,格式为 00 :00:00. 000

sql - 时态表中包含旧日期的种子数据 - SQL Server

SQL Server 并将时间分配为小时

Java 有界类型作为属性

java - Swagger-Codegen 不使用供应商扩展 x-discriminator-value

javascript - Javascript 减去日期

python - 如何将日期时间对象转换为毫秒

r - R中的时空聚类方法或包?