java.time.YearMonth 類



介紹

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)

返回減去指定 YearMonth 後的此 YearMonth 的副本。

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
廣告