java.time.OffsetDateTime.compareTo() 方法
描述
java.time.OffsetDateTime.compareTo(OffsetDateTime other) 方法将此日期时间与另一个日期时间进行比较。
声明
以下是 java.time.OffsetDateTime.compareTo(OffsetDateTime other) 方法的声明。
public int compareTo(OffsetDateTime other)
参数
other − 要比较的另一个日期时间,不为空。
返回值
比较器值,小于为负,大于为正。
示例
下面的例子展示了 java.time.OffsetDateTime.compareTo(OffsetDateTime other) 方法的使用。
package com.tutorialspoint;
import java.time.OffsetDateTime;
public class OffsetDateTimeDemo {
public static void main(String[] args) {
OffsetDateTime date = OffsetDateTime.parse("2017-02-03T12:30:30+01:00");
System.out.println(date);
OffsetDateTime date1 = OffsetDateTime.parse("2017-03-03T12:30:30+01:00");
System.out.println(date1);
System.out.println(date1.compareTo(date));
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
2017-02-03T12:30:30+01:00 2017-03-03T12:30:30+01:00 1

