我正在尝试将Joda LocalDate转换为Joda LocalDateTime,因为我使用的是toLocalDateTime(LocalTime.MIDNIGHT)方法,到目前为止,它工作得很好--例如:对于给定的joda 2025-02-28,我得到了预期的joda LocalDateTime 2025-02-28T00:00:00.000,但我担心的是,这个方法在所有情况下是否都能正常工作。例如during dayLight saving time zone anomalies..etc.
更新:我对这个问题做了一个小小的研究
toLocalDateTime(LocalTime time) 文档说:将LocalDate对象转换为带有LocalTime的LocalDateTime,以填充缺少的字段。
当我用LocalTime.MIDNIGHT初始化LocalTime时,这里 LocalTime.MIDNIGHT是初始化为new LocalTime(0, 0, 0, 0);的静态最后字段,您可以看到,使用ISOChronology getInstanceUTC()将值硬编码为零值,因此我认为可以在没有任何问题的情况下获得所需的输出。
发布于 2015-03-26 09:45:07
从文档,我们知道
我们还知道LocalDate类的LocalDate方法是像这那样实现的。
public LocalDateTime toLocalDateTime(LocalTime time) {
if (time == null) {
throw new IllegalArgumentException("The time must not be null");
}
if (getChronology() != time.getChronology()) {
throw new IllegalArgumentException("The chronology of the time does not match");
}
long localMillis = getLocalMillis() + time.getLocalMillis();
return new LocalDateTime(localMillis, getChronology());
}此外,考虑到UTC没有夏令时间。,我们可以得出结论,使用toLocalDateTime方法您不必担心夏时制问题或时区异常,因为这种方法不处理时区。
https://stackoverflow.com/questions/29272356
复制相似问题