It is my understanding that a ZonedDateTime
is really an enhanced version of an Instant
. It has all the data an Instant
has (precise value along UTC timeline), plus time zone information. So my naïve assumption was that a ZonedDateTime
is-an Instant
and that any method taking an Instant
will happily take a ZonedDateTime
instead. Furthermore, I expected isBefore()
, isAfter()
etc. to work seamlessly between Instant
s and ZonedDateTime
s.
Looking at the API documentation for Instant
and ZonedDateTime
, none of this is the case. I can compare Instant
s with Instant
s and ZonedDateTime
s with ZonedDateTime
s, but the two classes seem to be incompatible. What's more, third-party code like ThreeTen-Extra's Interval
seem to work exclusively with Instant
s.
Is there a reason why Instant
and ZonedDateTime
are not meant to be mixed?
LocalDateTime
coupled with a zone, note as anInstant
coupled with a zone. It has all the date-time fields, not an offset from a point in UTC. Why do you expect it to behave other than its documentation says? – ParamagnetismZonedDateTime
to anInstant
using.toInstant()
, but to convert from anInstant
to aZonedDateTime
, you must useZonedDateTime.ofInstant
and specify aZoneId
. – Bulb