object YearMonth extends Serializable
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.
- Annotations
- @SerialVersionUID()
- Alphabetic
- By Inheritance
- YearMonth
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
from(temporal: TemporalAccessor): YearMonth
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 ofYearMonth
.The conversion extracts the
YEAR
andMONTH_OF_YEAR
fields. The extraction is only permitted if the temporal object has an ISO chronology, or can be converted to aLocalDate
.This method matches the signature of the functional interface
TemporalQuery
allowing it to be used in queries via method reference,YearMonth::from
.- temporal
the temporal object to convert, not null
- returns
the year-month, not null
- Exceptions thrown
DateTimeException
if unable to convert to a { @code YearMonth}
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
now(clock: Clock): 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
.- clock
the clock to use, not null
- returns
the current year-month, not null
-
def
now(zone: ZoneId): YearMonth
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.
- zone
the zone ID to use, not null
- returns
the current year-month using the system clock, not null
-
def
now: YearMonth
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.
- returns
the current year-month using the system clock and default time-zone, not null
-
def
of(year: Int, month: Int): YearMonth
Obtains an instance of
YearMonth
from a year and month.Obtains an instance of
YearMonth
from a year and month.- year
the year to represent, from MIN_YEAR to MAX_YEAR
- month
the month-of-year to represent, from 1 (January) to 12 (December)
- returns
the year-month, not null
- Exceptions thrown
DateTimeException
if either field value is invalid
-
def
of(year: Int, month: Month): YearMonth
Obtains an instance of
YearMonth
from a year and month.Obtains an instance of
YearMonth
from a year and month.- year
the year to represent, from MIN_YEAR to MAX_YEAR
- month
the month-of-year to represent, not null
- returns
the year-month, not null
- Exceptions thrown
DateTimeException
if the year value is invalid
-
def
parse(text: CharSequence, formatter: DateTimeFormatter): YearMonth
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.
- text
the text to parse, not null
- formatter
the formatter to use, not null
- returns
the parsed year-month, not null
- Exceptions thrown
DateTimeParseException
if the text cannot be parsed
-
def
parse(text: CharSequence): YearMonth
Obtains an instance of
YearMonth
from a text string such as2007-12
.Obtains an instance of
YearMonth
from a text string such as2007-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.- text
the text to parse such as "2007-12", not null
- returns
the parsed year-month, not null
- Exceptions thrown
DateTimeParseException
if the text cannot be parsed
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )