1

The following code creates an instant representing the date 03/01/2000 with no time...

val instant = LocalDate.of(2000, 1, 3).atStartOfDay().toInstant(ZoneOffset.UTC)
println(instant) // 2000-01-03T00:00:00Z

Extracting the date from this instant throws an exception...

val date = LocalDate.from(instant)

java.time.DateTimeException: Unable to obtain LocalDate from TemporalAccessor: 2000-01-31T00:00:00Z of type java.time.Instant

Why, when the date is part of the instant, and how do I fix this?

Matthew Layton
  • 39,871
  • 52
  • 185
  • 313

0 Answers0