Search code examples
javadatelocaldatejava.util.date

Convert java.util.Date to LocalDate


I have to convert java.util.Date to LocalDate. I stole the example from here: Convert java.util.Date to java.time.LocalDate

but noticed something strange.

When I just use new LocalDate() then I see in debuger: enter image description here

but when I do: date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate() then in debuger I see: enter image description here

so insted of iLocalMillis there is year and so on. Which causes problems for me later. Why is that so? Can I have exactly the same details after conversion as in the new LocalDate()?


Solution

  • The fields in the first snapshot match the internal structure of an org.joda.time.LocalDate class.

    The fields in the second snapshot match the internal structure of a java.time.LocalDate class.

    So you are mixing two different LocalDate classes in your code.