手册
目录
收藏769
分享
阅读792
更新时间2025-07-22
前言:
在本教程中,您将学习如何使用java.time.Year类,简介java.time.Year类表示ISO-8601日历系统中的一年,例如2007。
java.time.Year 类表示 ISO-8601 日历系统中的一年,例如 2007。
以下是 java.time.Year 类的声明 −
public final class Year
   extends Object
      implements Temporal, TemporalAdjuster, Comparable, Serializable
 点击 "运行实例" 按钮查看在线实例
以下是 Java.time.Period 类的字段 −
static int MAX_VALUE − 支持的最大年份,'+999,999,999'。
static int MIN_VALUE − 支持的最小年份,'-999,999,999'。
| 序号 | 方法 & 描述 | 
|---|---|
| 1 | Temporal adjustInto(Temporal temporal)
 调整指定的时间对象有今年。  | 
| 2 | LocalDate atDay(int dayOfYear)
 将今年与一年中的某一天结合起来创建一个 LocalDate。  | 
| 3 | p>YearMonth atMonth(Month month)
 将今年与一个月结合起来创建一个 YearMonth。  | 
| 4 | p>YearMonth atMonth(月月)
 将今年与一个月结合起来创建一个 YearMonth。  | 
| 5 | p>LocalDate atMonthDay(MonthDay monthDay)
 结合今年和月日来创建 LocalDate。  | 
| 6 | int compareTo(Year other)
 将今年与另一年进行比较。  | 
| 7 | boolean equals(Object otherYear)
 检查今年是否等于指定的年份。  | 
| 8 | String format(DateTimeFormatter formatter)
 今年使用指定的格式化程序格式化。  | 
| 9 | static Year from(TemporalAmount amount)
 从时间量中获取 Year 的实例。  | 
| 10 | int get(TemporalField field)
 从今年获取指定字段的值作为 int。  | 
| 11 | long getLong(TemporalField field)
 获取请求单位的值。  | 
| 12 | int getValue()
 获取年份值。  | 
| 13 | int hashCode()
 今年的哈希码。  | 
| 14 | boolean isAfter(Year other)
 检查今年是否在指定年份之后。  | 
| 15 | boolean isBefore(Year other)
 检查今年是否在指定年份之前。  | 
| 16 | boolean isLeap()
 根据 ISO 预测日历系统规则检查年份是否为闰年。  | 
| 17 | boolean isLeap(long year)
 根据 ISO 预测日历系统规则检查年份是否为闰年。  | 
| 18 | boolean isSupported(TemporalField field)
 检查是否支持指定的字段。  | 
| 19 | boolean isSupported(TemporalUnit unit)
 检查是否支持指定的单位。  | 
| 20 | boolean isValidMonthDay(MonthDay monthDay)
 检查今年的月日是否有效。  | 
| 21 | int length()
 获取今年的天数。  | 
| 22 | Year minus(long amountToSubtract, TemporalUnit unit)
 返回今年减去指定数量的副本。  | 
| 23 | Year minus(TemporalAmount amountToSubtract)
 返回今年减去指定年份的副本。  | 
| 24 | Year minusYears(long yearsToSubtract)
 返回今年减去指定年份的副本。  | 
| 25 | static Year now()
 从默认时区的系统时钟获取当前年份。  | 
| 26 | static Year now(Clock clock)
 从指定时钟获取当前年份。  | 
| 27 | static Year now(ZoneId zone)
 从指定时区的系统时钟获取当前年份。  | 
| 28 | static Year of(int years)
 获取 Year 的实例。  | 
| 29 | static Year parse(CharSequence text)
 从 2007 等文本字符串中获取年份。  | 
| 30 | static Year parse(CharSequence text, DateTimeFormatter formatter)
 使用特定格式化程序从文本字符串中获取 Year 的实例。  | 
| 31 | Year plus(long amountToAdd, TemporalUnit unit)
 返回添加了指定年份的该年份的副本。  | 
| 32 | Year plus(TemporalAmount amountToAdd)
 返回添加了指定年份的该年份的副本。  | 
| 33 | Year plusMonths(long monthsToAdd) 返回添加了指定月份的今年的副本。  | 
| 34 | Year plusYears(long yearsToAdd)
 返回添加了指定年份的今年的副本。  | 
| 35 | 使用指定查询查询今年。  | 
| 36 | ValueRange range(TemporalField field)
 获取指定字段的有效值范围。  | 
| 37 | String toString()
 以字符串形式输出今年。  | 
| 38 | long until(Temporal endExclusive, TemporalUnit unit)
 以指定单位计算距离另一年的时间量。  | 
| 39 | Year with(TemporalAdjuster adjuster)
 返回今年的调整副本。  | 
这个类继承了以下类的方法 −
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
							
							共5课时
17.2万人学习
							
							共49课时
77万人学习
							
							共29课时
61.7万人学习
							
							共25课时
39.3万人学习
							
							共43课时
70.9万人学习
							
							共25课时
61.6万人学习
							
							共22课时
23万人学习
							
							共28课时
33.9万人学习
							
							共89课时
125万人学习