Given ZonedDateTime, calling toString, then ZonedDateTime.parsein some cases returns a different time.
Here is an example. The code is in Scala, but it is no different from Java.
import java.time._
val t = 1193534827725L
val z = ZoneId.of("Europe/Paris")
val a = Instant.ofEpochMilli(t).atZone(z) // 2007-10-28T02:27:07.725+01:00[Europe/Paris]
val b = ZonedDateTime.parse(a.toString) // 2007-10-28T02:27:07.725+02:00[Europe/Paris]
a == b // returns false!
The reanalyzed value also has a different era of Milli:
scala> List(a, b).map(_.toInstant.toEpochMilli)
res46: List[Long] = List(1193534827725, 1193531227725)
scala> List(a, b).map(_.toInstant.toEpochMilli == t)
res47: List[Boolean] = List(true, false)
Using .format(DateTimeFormatter.ISO_ZONED_DATE_TIME)instead .toStringdoes not work either.
According to the Javadoc for Instant#atZonewhich is rejected https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html#ofInstant-java.time.Instant-java.time.ZoneId-
Converting a moment to a zoned date-time is simple because there is only one valid offset for each moment.
What's happening?
: , (ref), 02:27:07.725. .toString, , , , .