我有一个长时间戳 1499070300(相当于 2017 年 7 月 3 日星期一 16:25:00 +0800),但是当我将其转换为 LocalDateTime 时,我得到 1970-01-18T16:24:30.300
这是我的代码
long test_timestamp = 1499070300;
LocalDateTime triggerTime =
LocalDateTime.ofInstant(Instant.ofEpochMilli(test_timestamp), TimeZone
.getDefault().toZoneId());
最佳答案
您需要以毫秒为单位传递时间戳:
long test_timestamp = 1499070300000L;
LocalDateTime triggerTime =
LocalDateTime.ofInstant(Instant.ofEpochMilli(test_timestamp),
TimeZone.getDefault().toZoneId());
System.out.println(triggerTime);
结果:
2017-07-03T10:25
或者使用 ofEpochSecond
代替:
long test_timestamp = 1499070300L;
LocalDateTime triggerTime =
LocalDateTime.ofInstant(Instant.ofEpochSecond(test_timestamp),
TimeZone.getDefault().toZoneId());
System.out.println(triggerTime);
结果:
2017-07-03T10:25
关于java - LocalDateTime 的长时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44883432/