Close

Java Date Time - OffsetDateTime.timeLineOrder() 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 static Comparator<OffsetDateTime> timeLineOrder()

This static method returns a comparator that compares two OffsetDatetime instances based on the timeline Instance. Note that the instance method compareTo(OffSetDateTime) also uses the same static method internally, which if returns 0 then two instances are compare based on LocalDatetime:

this.toLocalDateTime().compareTo(other.toLocalDateTime());


Examples


package com.logicbig.example.offsetdatetime;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class TimeLineOrderExample {

public static void main(String... args) {
OffsetDateTime d1 = OffsetDateTime.of(2015, 11, 15, 18,
20, 30, 100, ZoneOffset.ofHours(-5));

OffsetDateTime d2 = OffsetDateTime.of(2015, 11, 15, 18,
20, 30, 100, ZoneOffset.ofHours(-5));

int i = OffsetDateTime.timeLineOrder().compare(d1, d2);
System.out.println(i);
}
}

Output

0




See Also