gpt4 book ai didi

java - 将 java.time.temporal.Temporal 转换为 java.util.Date

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:37:03 28 4
gpt4 key购买 nike

如何将 java.time.temporal.Temporal 实例转换为 java.util.Date 实例?

java.time.temporal.Temporal someTemporal = Instant.now();
java.util.Date some Temporal = x(someTemporal);

我看过Oracle's legacy time trail documentation , 但找不到合适的解决方案。

最佳答案

我强烈建议省略对(过于)通用接口(interface) java.time.temporal.Temporal 的任何引用,只需执行以下操作:

java.util.Date some = java.util.Date.from(Instant.now());

使用接口(interface) Temporal 几乎就像使用 java.lang.Object 一样。您应该尽可能具体(尤其是在日期和时间的上下文中)。甚至 JSR-310-API officially outputs a warning :

This interface is a framework-level interface that should not be widely used in application code. Instead, applications should create and pass around instances of concrete types, such as LocalDate. There are many reasons for this, part of which is that implementations of this interface may be in calendar systems other than ISO. See ChronoLocalDate for a fuller discussion of the issues.

关于java - 将 java.time.temporal.Temporal 转换为 java.util.Date,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40221774/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com