Java Date Time Java Java API
java.time.OffsetDateTime
public boolean isEqual(OffsetDateTime other)
Checks if the instant of this OffsetDateTime is equal to that of the specified one.
This is equivalent to using dateTime1.toInstant().equals(dateTime2.toInstant()).
dateTime1.toInstant().equals(dateTime2.toInstant())
package com.logicbig.example.offsetdatetime;import java.time.*;public class IsEqualExample { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2010, 10, 3, 12, 0), ZoneOffset.ofHours(-6)); OffsetDateTime d2 = OffsetDateTime.of(LocalDate.of(2010, 10, 3), LocalTime.NOON, ZoneOffset.ofHours(-5)); boolean b = d.isEqual(d2); System.out.println(b); }}
false
package com.logicbig.example.offsetdatetime;import java.time.LocalDate;import java.time.LocalDateTime;import java.time.LocalTime;import java.time.OffsetDateTime;import java.time.ZoneOffset;public class IsEqualExample2 { public static void main (String... args) { OffsetDateTime d = OffsetDateTime.of(LocalDateTime.of(2010, 10, 3, 11, 0), ZoneOffset.ofHours(-6)); OffsetDateTime d2 = OffsetDateTime.of(LocalDate.of(2010, 10, 3), LocalTime.NOON, ZoneOffset.ofHours(-5)); boolean b = d.isEqual(d2); System.out.println(b); }}
true