0


None of these classes have Zone information:

java.util.Date (no Zone information)
java.time.Instant (no Zone information)
java.time.LocalDate (no Zone information)

But according to this question: Convert java.util.Date to java.time.LocalDate the Zone information must be provided to do the conversion.

LocalDate date = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

Zone Date LocalDate

As the image can elucidate we start from an instant without Zone information and we end up in the same point without Zone information.

Why provide the Zone information for the conversion between java.util.Date and java.time.LocalDate?

fidudidu
  • 399
  • 3
  • 10
  • 1
    It's explained in the accepted answer in that question. – Sotirios Delimanolis Nov 22 '19 at 15:09
  • 1
    Said differently: at that instant/moment, what is the `LocalDate` at a given time zone. You're not just extracting the day/month/year from the instant. Is that what you're trying to do? – Sotirios Delimanolis Nov 22 '19 at 15:11
  • 1
    The `LocalDate` is not a point on the timeline, so the picture is wrong. The same `LocalDate` can express a different instant, depending on the timezone. It’s correct that neither, `Instant` nor `LocalDate` contain a timezone, but that’s irrelevant. For example, neither, “day of week” nor “day of month”, contain a month or year, so why do I need month and year to convert between “day of month” to “day of week”… – Holger Jan 24 '20 at 10:41

0 Answers0