java.time.OffsetDateTime.compareTo(OffsetDateTime other)
方法将此日期时间与另一个日期时间进行比较。
声明
以下是java.time.OffsetDateTime.compareTo(OffsetDateTime other)
方法的声明。
public int compareTo(OffsetDateTime other)
参数
other
- 要比较的其他日期时间,而不是null
。
返回值
比较器值,如果更小则为负,如果更大则为正。
示例
以下示例显示了java.time.OffsetDateTime.compareTo(OffsetDateTime other)
方法的用法。
package com.zaixian;
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