如何在JAVA中将时间戳转换为13位十进制数。

huangapple go评论67阅读模式
英文:

How to convert timestamp to 13 digit decimal in JAVA

问题

在Java中是否有用于将时间戳解析为十进制的函数?

输入:2023-07-04 00:00:00.0

预期输出:1687771449497

英文:

Is there some function in Java, for parsing timestamp to decimal?

Input: 2023-07-04 00:00:00.0

Expected output: 1687771449497

答案1

得分: 1

如果在Java代码中用LocalDateTime来表示时间戳,您可以使用以下方法将时间戳转换为纪元毫秒:

LocalDateTime localDateTime = LocalDateTime.of(2023, 7, 4, 0, 0);
ZonedDateTime zdt = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
long millis = zdt.toInstant().toEpochMilli();
英文:

If you're using LocalDateTime for you timestamp representation in Java code, so you can you the following approach to convert timestamp into epoch millis:

LocalDateTime localDateTime = LocalDateTime.of(2023, 7, 4, 0, 0);
ZonedDateTime zdt = ZonedDateTime.of(localDateTime, ZoneId.systemDefault());
long millis = zdt.toInstant().toEpochMilli();

huangapple
  • 本文由 发表于 2023年7月3日 14:43:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定