简体   繁体   English

将java.util.Date转换为LocalDate

[英]Convert java.util.Date to LocalDate

I have to convert java.util.Date to LocalDate. 我必须将java.util.Date转换为LocalDate。 I stole the example from here: Convert java.util.Date to java.time.LocalDate 我从这里窃取了示例: 将java.util.Date转换为java.time.LocalDate

but noticed something strange. 但是注意到了一些奇怪的事情。

When I just use new LocalDate() then I see in debuger: 当我只使用new LocalDate()我会在调试器中看到: 在此处输入图片说明

but when I do: date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() then in debuger I see: 但是当我这样做时: date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()然后在date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate()中我看到: 在此处输入图片说明

so insted of iLocalMillis there is year and so on. 因此安装了iLocalMillisyear等等。 Which causes problems for me later. 以后给我造成麻烦。 Why is that so? 为什么会这样? Can I have exactly the same details after conversion as in the new LocalDate() ? 转换后,我可以拥有与new LocalDate()完全相同的详细信息吗?

The fields in the first snapshot match the internal structure of an org.joda.time.LocalDate class. 第一个快照中的字段与org.joda.time.LocalDate类的内部结构匹配。

The fields in the second snapshot match the internal structure of a java.time.LocalDate class. 第二个快照中的字段与java.time.LocalDate类的内部结构匹配。

So you are mixing two different LocalDate classes in your code. 因此,您在代码中混合了两个不同的LocalDate类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM