- java.time 包中的类
- java.time - 主页
- java.time - 时钟
- java.time - 持续时间
- java.time - 即时
- java.time - 本地日期
- java.time - 本地日期时间
- java.time - 本地时间
- java.time - 月日
- java.time - 偏移日期时间
- java.time - 偏移时间
- java.time - 周期
- java.time - 年份
- java.time - 年月
- java.time - 区域日期时间
- java.time - 区域 ID
- java.time - 区域偏移
- java.time 包中的枚举
- java.time - 月份
- java.time 有用资源
- java.time - 讨论
java.time.Year.compareTo() 方法示例
描述
java.time.Year.compareTo(Year other) 方法将本年与另一个年份进行比较。
声明
以下是对 java.time.Year.compareTo(Year other) 方法的声明。
public int compareTo(Year other)
参数
other - 要比较的其他年份,非空。
返回值
比较值,小于则为负数,大于则为正数。
示例
以下示例演示了 java.time.Year.compareTo(Year other) 方法的用法。
package com.tutorialspoint;
import java.time.Year;
public class YearDemo {
public static void main(String[] args) {
Year date = Year.of(2005);
Year date1 = Year.of(2006);
System.out.println(date.compareTo(date1));
}
}
让我们编译并运行以上程序,这将产生以下结果 -
-1
广告