如何计算1800的纳秒

发布于 2025-02-05 20:56:41 字数 1551 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒废 2025-02-12 20:56:41

即时仍然是最佳选择,但是您可能需要一些辅助对象。

例如,创建开始日期(根据需要替换z,请根据需要替换):

Instant start = Instant.parse("1831-11-11T00:00:00Z");

然后进行给定的日期。您可以解析它,也可以使用转换方法。例如,如果您有一个localdateTime(使用不同的ZeardIDZoneOffset根据需要):

LocalDateTime localDateTime = LocalDateTime.parse("2022-06-09T20:56");
Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();

现在获取持续时间:

Duration duration = Duration.between(start, instant);
long nanos = duration.toNanos();

Instant is still the best option, but you may need some helper objects.

For instance, to create the start date (replace the Z with a different time zone or offset as needed):

Instant start = Instant.parse("1831-11-11T00:00:00Z");

Then take the given date. You can parse it, or use conversion methods. For instance, if you have a LocalDateTime (use a different ZoneId or ZoneOffset as needed):

LocalDateTime localDateTime = LocalDateTime.parse("2022-06-09T20:56");
Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();

Now get a duration:

Duration duration = Duration.between(start, instant);
long nanos = duration.toNanos();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文