java.time.YearMonth 类
在本教程中,您将学习如何使用java.time.YearMonth类,简介java.time.YearMonth类表示ISO-8601日历系统中的年月,例如2007-12。
java.time.YearMonth 类表示 ISO-8601 日历系统中的年月,例如 2007-12。
类声明
以下是 java.time.YearMonth 类的声明 −
public final class YearMonth extends Object implements Temporal, TemporalAdjuster, Comparable<YearMonth>, Serializable
运行实例 »
点击 "运行实例" 按钮查看在线实例
类方法
序号 | 方法 & 描述 |
---|---|
1 | Temporal adjustInto(Temporal temporal)
将指定的时间对象调整为具有此年月。 |
2 | LocalDate atDay(int dayOfMonth)
将本年月与月日结合起来创建一个 LocalDate。 |
3 | LocalDate atEndOfMonth()
返回月底的 LocalDate.. |
4 | int compareTo(YearMonth other)
将本年月与另一年月进行比较。 |
5 | boolean equals(Object otherYearMonth)
检查此 YearMonth 是否等于指定的 YearMonth。 |
6 | String format(DateTimeFormatter formatter)
使用指定的格式化程序格式化今年的月份。 |
7 | static YearMonth from(TemporalAmount amount)
从时间量中获取 YearMonth 的实例。 |
8 | int get(TemporalField field)
以 int 形式获取本年月中指定字段的值。 |
9 | long getLong(TemporalField field)
获取所请求单位的值。 |
10 | Month getMonth()
使用 Month 枚举获取月份字段。 |
11 | int getMonthValue()
获取从 1 到 12 的月份字段。 |
12 | int getYear()
获取年份字段。 |
13 | int hashCode()
这个 YearMonth 的哈希码。 |
14 | boolean isAfter(YearMonth other)
检查本年月是否在指定年月之后。 |
15 | boolean isBefore(YearMonth other)
检查这个年月是否在指定的年月之前。 |
16 | boolean isLeapYear()
根据 ISO 预测日历系统规则检查年份是否为闰年。 |
17 | boolean isLeap(long year)
根据 ISO 预测日历系统规则检查年份是否为闰年。 |
18 | boolean isSupported(TemporalField field)
检查是否支持指定的字段。 |
19 | boolean isSupported(TemporalUnit unit)
检查是否支持指定的单位。 |
20 | boolean isValidDay(int dayOfMonth)
检查月份中的某天是否适用于该年份的月份。 |
21 | int lengthOfMonth()
返回月份的长度,考虑到年份。 |
22 | int lengthOfYear()
返回年份的长度。 |
23 | YearMonth minus(long amountToSubtract, TemporalUnit unit)
返回今年减去指定数量的副本。 |
24 | YearMonth minus(TemporalAmount amountToSubtract)
返回减去指定年月的本年月的副本。 |
25 | YearMonth minusMonths(long monthsToSubtract)
返回减去指定月份的 YearMonth 的副本。 |
26 | YearMonth minusYears(long yearsToSubtract)
返回此 YearMonth 的副本,减去指定的年份。 |
27 | static YearMonth now()
从默认时区的系统时钟获取当前年月。 |
28 | static YearMonth now(Clock clock)
从指定的时钟获取当前的年月。 |
29 | static YearMonth now(ZoneId zone)
从指定时区的系统时钟获取当前年月。 |
30 | static YearMonth of(int years, int month)
从年份和月份中获取 YearMonth 的实例。 |
31 | static YearMonth of(int years, Month month)
从年份和月份中获取 YearMonth 的实例。 |
32 | static YearMonth parse(CharSequence text)
从诸如 2007-12 的文本字符串中获取 YearMonth。 |
33 | static YearMonth parse(CharSequence text, DateTimeFormatter formatter)
使用特定格式化程序从文本字符串中获取 YearMonth 的实例。 |
34 | YearMonth plus(long amountToAdd, TemporalUnit unit)
返回此 YearMonth 的副本,并添加了指定的 YearMonth。 |
35 | YearMonth plus(TemporalAmount amountToAdd)
返回此 YearMonth 的副本,并添加了指定的 YearMonth。 |
36 | YearMonth plusMonths(long monthsToAdd)
返回此 YearMonth 的副本,其中添加了指定的月份。 |
37 | YearMonth plusYears(long yearsToAdd)
返回此 YearMonth 的副本,其中添加了指定的年份。 |
38 | <R> R query(TemporalQuery<R> query)
使用指定的查询查询本年-月。 |
39 | ValueRange range(TemporalField field)
获取指定字段的有效值范围。 |
40 | String toString()
以字符串的形式输出这一年的月份。 |
41 | long until(Temporal endExclusive, TemporalUnit unit)
以指定单位计算距离另一个年月的时间量。 |
42 | YearMonth with(TemporalAdjuster adjuster)
返回今年月的调整副本。 |
43 | YearMonth with(TemporalField field, long newValue)
返回此年月的副本,并将指定字段设置为新值。 |
44 | YearMonth withMonth(int month)
返回此 YearMonth 的副本,其中更改了年份。 |
45 | YearMonth withYear(int year)
返回此 YearMonth 的副本,其中年份已更改。 |
继承的方法
这个类继承了以下类的方法 −
- Java.lang.Object