您能否说明如何为默认系统时区和给定时区获取正确的纪元时间(以毫秒为单位).
1.时区:GMT+3
2.以下代码片段:
import java.time.*; public class Main { public static void main(String[] args) { System.out.println(LocalDateTime .now() .atZone(ZoneOffset.UTC) .toInstant() .toEpochMilli() ); System.out.println(LocalDateTime .now() .atZone(ZoneOffset.of("+3")) .toInstant() .toEpochMilli() ); System.out.println(System.currentTimeMillis()); } }
3.输出:
1444158955508 1444148155508 1444148155508
4.System.currentTimeMillis() 的 JavaDoc 表示返回值将是当前时间与 UTC 1970 年 1 月 1 日午夜之间的差异,以毫秒为单位.
- GMT+3 的 LocalDateTime 的输出与 System.currentTimeMillis() 的输出相同,尽管 LocalDateTime 的文档code>System.currentTimeMillis() 提到 UTC?
- UTC 的 LocalDateTime 输出不同于 System.currentTimeMillis(),尽管 System.currentTimeMillis 的文档() 提到 UTC?
- the output of the LocalDateTime at GMT+3 is the same as of System.currentTimeMillis(),although the docs for the System.currentTimeMillis() mention UTC?
- the output of the LocalDateTime at UTC differs from System.currentTimeMillis(),although the docs for the System.currentTimeMillis() mention UTC?