1

我的 Time4J 库有问题,我无法将特定的时间戳转换为 Moment 格式。

例如,我想要这样的东西:Moment.timeInMillies = myTimeMoment.of(myTime)

myTimelong自纪元以来的毫秒值,可以通过System.currentTimeMillis().

4

1 回答 1

3

编辑:我认为最好的转换是

TemporalType.MILLIS_SINCE_UNIX.translate(myTime)

MILLIS_SINCE_UNIX可以在Longand之间转换Moment,因此调用会隐式地将您的long.

原始答案:我没有经验,但我阅读文档的方式应该可以:

  • Moment.of(myTime / 1000, Math.toIntExact(myTime % 1000 * 1_000_000), TimeScale.POSIX)
  • Moment.from(Instant.ofEpochMilli(myTime))

不过,我可能错过了一种更优雅的方式,我不知道。

链接

于 2019-07-10T19:46:21.473 回答