java.time.YearMonth.compareTo(YearMonth other)
方法将此年份与另一个月份进行比较。
声明
以下是java.time.YearMonth.compareTo(YearMonth other)
方法的声明。
public int compareTo(YearMonth other)
参数
other
- 与之比较的另一个年月,而不是null
。
返回值
比较器值,如果小则返回负值,如果大则返回正值。
示例
以下示例显示了java.time.YearMonth.compareTo(YearMonth other)
方法的用法。
package com.yiibai;
import java.time.YearMonth;
public class YearMonthDemo {
public static void main(String[] args) {
YearMonth date = YearMonth.of(2005,11);
YearMonth date1 = YearMonth.of(2006,11);
System.out.println(date.compareTo(date1));
}
}
编译并运行上面的程序,这将产生以下结果 -
-1