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()

獲取月份字段112之間的值。

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 query(TemporalQuery 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