Obtains an instance of YearMonth
from a temporal object.
Obtains an instance of YearMonth
from a temporal object.
A TemporalAccessor
represents some form of date and time information.
This factory converts the arbitrary temporal object to an instance of YearMonth
.
The conversion extracts the YEAR
and
MONTH_OF_YEAR
fields.
The extraction is only permitted if the temporal object has an ISO
chronology, or can be converted to a LocalDate
.
This method matches the signature of the functional interface TemporalQuery
allowing it to be used in queries via method reference, YearMonth::from
.
the temporal object to convert, not null
the year-month, not null
DateTimeException
if unable to convert to a { @code YearMonth}
Obtains the current year-month from the specified clock.
Obtains the current year-month from the specified clock.
This will query the specified clock to obtain the current year-month.
Using this method allows the use of an alternate clock for testing.
The alternate clock may be introduced using dependency injection
.
the clock to use, not null
the current year-month, not null
Obtains the current year-month from the system clock in the specified time-zone.
Obtains the current year-month from the system clock in the specified time-zone.
This will query the system clock
to obtain the current year-month.
Specifying the time-zone avoids dependence on the default time-zone.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
the zone ID to use, not null
the current year-month using the system clock, not null
Obtains the current year-month from the system clock in the default time-zone.
Obtains the current year-month from the system clock in the default time-zone.
This will query the system clock
in the default
time-zone to obtain the current year-month.
The zone and offset will be set based on the time-zone in the clock.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
the current year-month using the system clock and default time-zone, not null
Obtains an instance of YearMonth
from a year and month.
Obtains an instance of YearMonth
from a year and month.
the year to represent, from MIN_YEAR to MAX_YEAR
the month-of-year to represent, from 1 (January) to 12 (December)
the year-month, not null
DateTimeException
if either field value is invalid
Obtains an instance of YearMonth
from a year and month.
Obtains an instance of YearMonth
from a year and month.
the year to represent, from MIN_YEAR to MAX_YEAR
the month-of-year to represent, not null
the year-month, not null
DateTimeException
if the year value is invalid
Obtains an instance of YearMonth
from a text string using a specific formatter.
Obtains an instance of YearMonth
from a text string using a specific formatter.
The text is parsed using the formatter, returning a year-month.
the text to parse, not null
the formatter to use, not null
the parsed year-month, not null
DateTimeParseException
if the text cannot be parsed
Obtains an instance of YearMonth
from a text string such as 2007-12
.
Obtains an instance of YearMonth
from a text string such as 2007-12
.
The string must represent a valid year-month.
The format must be yyyy-MM
.
Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
the text to parse such as "2007-12", not null
the parsed year-month, not null
DateTimeParseException
if the text cannot be parsed
A year-month in the ISO-8601 calendar system, such as
2007-12
.YearMonth
is an immutable date-time object that represents the combination of a year and month. Any field that can be derived from a year and month, such as quarter-of-year, can be obtained.This class does not store or represent a day, time or time-zone. For example, the value "October 2007" can be stored in a
YearMonth
.The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.
Specification for implementors
This class is immutable and thread-safe.