You check the equality of the object, which evaluates to false , since these objects are not equivalent. One is associated with ZoneId , and the other is with ZoneOffset . If you want to check if they represent the same time, you can use the not very intuitively named isEqual method.
eg:.
ZoneId zid = ZoneId.of("America/New_York"); ZoneOffset offset = ZoneOffset.from(LocalDateTime.now().atZone(zid)); ZonedDateTime zdt0 = ZonedDateTime.of(2014, 8, 24, 21, 10, 1, 777000002, offset); ZonedDateTime zdt1 = ZonedDateTime.of(2014, 8, 24, 21, 10, 1, 777000002, zid); System.out.println("isEqual:" + zdt0.isEqual(zdt1)); System.out.println("equals: " + zdt0.equals(zdt1));
prints:
isEqual:true equals: false
Btw, note that you do not need to use Objects.equals(a,b) for two objects that, as you already know, were not null . You can directly call a.equals(b) .
source share