Java Date Time Java Java API
java.time.OffsetTime
public boolean isEqual(OffsetTime other)
Checks if this OffsetTime is equal to the specified one.
It converts both instances to epoch nanos for comparison:
public boolean isEqual(OffsetTime other) { return toEpochNano() == other.toEpochNano();}
package com.logicbig.example.offsettime;import java.time.OffsetTime;import java.time.ZoneOffset;public class IsEqualExample { public static void main(String... args) { OffsetTime d1 = OffsetTime.of(17, 40, 33, 20000, ZoneOffset.ofHours(-6)); System.out.println(d1); OffsetTime d2 = OffsetTime.of(10, 40, 33, 20000, ZoneOffset.ofHours(-6)); System.out.println(d2); boolean equal = d1.isEqual(d2); System.out.println(equal); }}
17:40:33.000020-06:0010:40:33.000020-06:00false
package com.logicbig.example.offsettime;import java.time.OffsetTime;import java.time.ZoneOffset;public class IsEqualExample2 { public static void main(String... args) { OffsetTime d1 = OffsetTime.of(17, 40, 33, 20000, ZoneOffset.ofHours(-6)); System.out.println(d1); OffsetTime d2 = OffsetTime.of(10, 40, 33, 20000, ZoneOffset.ofHours(-13)); System.out.println(d2); boolean equal = d1.isEqual(d2); System.out.println("isEqual(): " + equal); System.out.println("equals(): " + d1.equals(d2)); System.out.println("compare(): " + d1.compareTo(d2)); }}
17:40:33.000020-06:0010:40:33.000020-13:00isEqual(): trueequals(): falsecompare(): 1