Skip to content

Instantly share code, notes, and snippets.

@will-molloy
Last active August 12, 2019 08:52
Show Gist options
  • Save will-molloy/ecd1d31d7d7a0835b5fda21d3e57c374 to your computer and use it in GitHub Desktop.
Save will-molloy/ecd1d31d7d7a0835b5fda21d3e57c374 to your computer and use it in GitHub Desktop.
Java time API (JSR 310) is smarter than initially thought
public static void main(String[] args) {
ZonedDateTime auckland = ZonedDateTime.of(LocalDateTime.of(2019, Month.AUGUST, 12, 20, 45), ZoneId.of("Pacific/Auckland"));
ZonedDateTime london = ZonedDateTime.of(LocalDateTime.of(2019, Month.AUGUST, 12, 9, 45), ZoneId.of("Europe/London"));
System.out.println(auckland.equals(london)); // false
System.out.println(auckland.isEqual(london)); // true
auckland = ZonedDateTime.of(LocalDateTime.of(2019, Month.DECEMBER, 12, 20, 45), ZoneId.of("Pacific/Auckland"));
london = ZonedDateTime.of(LocalDateTime.of(2019, Month.DECEMBER, 12, 7, 45), ZoneId.of("Europe/London"));
System.out.println(auckland.equals(london)); // false
System.out.println(auckland.isEqual(london)); // true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment