Close

Java Date Time - OffsetDateTime.isEqual() Examples

Java Date Time Java Java API 


Class:

java.time.OffsetDateTime

java.lang.Objectjava.lang.Objectjava.time.OffsetDateTimejava.time.OffsetDateTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Method:

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()).



Examples


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);
}
}

Output

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);
}
}

Output

true




See Also