The main date and time API is built on the ISO calendar system. The chronology operates behind the scenes to represent the general concept of a calendar system. For example, the Japanese, Minguo, Thai Buddhist and others.
Most other calendar systems also operate on the shared concepts of year, month and day,
linked to the cycles of the Earth around the Sun, and the Moon around the Earth.
These shared concepts are defined by ChronoField
and are available
for use by any Chronology
implementation:
LocalDate isoDate = ... ThaiBuddhistDate thaiDate = ... int isoYear = isoDate.get(ChronoField.YEAR); int thaiYear = thaiDate.get(ChronoField.YEAR);As shown, although the date objects are in different calendar systems, represented by different
Chronology
instances, both can be queried using the same constant on ChronoField
.
For a full discussion of the implications of this, see ChronoLocalDate
.
In general, the advice is to use the known ISO-based LocalDate
, rather than
ChronoLocalDate
.
While a Chronology
object typically uses ChronoField
and is based on
an era, year-of-era, month-of-year, day-of-month model of a date, this is not required.
A Chronology
instance may represent a totally different kind of calendar system,
such as the Mayan.
In practical terms, the Chronology
instance also acts as a factory.
The of(String)
method allows an instance to be looked up by identifier,
while the ofLocale(Locale)
method allows lookup by locale.
The Chronology
instance provides a set of methods to create ChronoLocalDate
instances.
The date classes are used to manipulate specific dates.
dateNow()
dateNow(clock)
dateNow(zone)
date(yearProleptic, month, day)
date(era, yearOfEra, month, day)
dateYearDay(yearProleptic, dayOfYear)
dateYearDay(era, yearOfEra, dayOfYear)
date(TemporalAccessor)
Chronology
, ChronoLocalDate
and Era
.
The majority of the logic specific to the calendar system will be in the
ChronoLocalDate
implementation.
The Chronology
implementation acts as a factory.
To permit the discovery of additional chronologies, the ServiceLoader
is used. A file must be added to the META-INF/services
directory with the
name 'java.time.chrono.Chronology' listing the implementation classes.
See the ServiceLoader for more details on service loading.
For lookup by id or calendarType, the system provided calendars are found
first followed by application provided calendars.
Each chronology must define a chronology ID that is unique within the system. If the chronology represents a calendar system defined by the CLDR specification then the calendar type is the concatenation of the CLDR type and, if applicable, the CLDR variant.
Implementation Specification
This interface must be implemented with care to ensure other classes operate correctly. All implementations that can be instantiated must be final, immutable and thread-safe. Subclasses should be Serializable wherever possible.
Modifier and Type | Method and Description |
---|---|
public int | Returns: the comparator value, that is this ID string compared with theother 's ID string
unless the ID strings are equal and
the chronology distinguishes instances using additional informationthe other chronology to compare to, not null other)Redeclares java. Compares this chronology to another chronology. |
public default ChronoLocalDate | Returns: the local date in this chronology, not nullthe era of the correct type for the chronology, not null era, int the chronology year-of-era yearOfEra, int the chronology month-of-year month, int the chronology day-of-month dayOfMonth)Obtains a local date in this chronology from the era, year-of-era, month-of-year and day-of-month fields. |
public ChronoLocalDate | Returns: the local date in this chronology, not nullthe chronology proleptic-year prolepticYear, int the chronology month-of-year month, int the chronology day-of-month dayOfMonth)Obtains a local date in this chronology from the proleptic-year, month-of-year and day-of-month fields. |
public ChronoLocalDate | Returns: the local date in this chronology, not nullthe temporal object to convert, not null temporal)Obtains a local date in this chronology from another temporal object. |
public ChronoLocalDate | Returns: the local date in this chronology, not nullthe epoch day epochDay)Obtains a local date in this chronology from the epoch-day. |
public default ChronoLocalDate | Returns: the current local date using the system clock and default time-zone, not nullObtains the current local date in this chronology from the system clock in the default time-zone. |
public default ChronoLocalDate | |
public default ChronoLocalDate | |
public default ChronoLocalDate | Returns: the local date in this chronology, not nullthe era of the correct type for the chronology, not null era, int the chronology year-of-era yearOfEra, int the chronology day-of-year dayOfYear)Obtains a local date in this chronology from the era, year-of-era and day-of-year fields. |
public ChronoLocalDate | Returns: the local date in this chronology, not nullthe chronology proleptic-year prolepticYear, int the chronology day-of-year dayOfYear)Obtains a local date in this chronology from the proleptic-year and day-of-year fields. |
public default long | Returns: the number of seconds relative to 1970-01-01T00:00:00Z, may be negativethe chronology proleptic-year prolepticYear, int the chronology month-of-year month, int the chronology day-of-month dayOfMonth, int the hour-of-day, from 0 to 23 hour, int the minute-of-hour, from 0 to 59 minute, int the second-of-minute, from 0 to 59 second, ZoneOffset the zone offset, not null zoneOffset)Gets the number of seconds from the epoch of 1970-01-01T00:00:00Z. |
public default long | Returns: the number of seconds relative to 1970-01-01T00:00:00Z, may be negativethe era of the correct type for the chronology, not null era, int the chronology year-of-era yearOfEra, int the chronology month-of-year month, int the chronology day-of-month dayOfMonth, int the hour-of-day, from 0 to 23 hour, int the minute-of-hour, from 0 to 59 minute, int the second-of-minute, from 0 to 59 second, ZoneOffset the zone offset, not null zoneOffset)Gets the number of seconds from the epoch of 1970-01-01T00:00:00Z. |
public boolean | |
public Era | Returns: the calendar system era, not nullthe era value eraValue)Creates the chronology era object from the numeric value. |
public List | Returns: the list of eras for the chronology, may be immutable, not nullGets the list of eras for the chronology. |
public static Chronology | Returns: the chronology, not nullthe temporal to convert, not null temporal)Obtains an instance of |
public static Set | Returns: the independent, modifiable set of the available chronology IDs, not nullReturns the available chronologies. |
public String | Returns: the calendar system type, null if the calendar is not defined by CLDR/LDMLGets the calendar type of the calendar system. |
public default String | Returns: the text value of the chronology, not nullthe style of the text required, not null style, Locale the locale to use, not null locale)Gets the textual representation of this chronology. |
public String | |
public int | |
public default boolean | Returns: true only if all the fields of IsoFields are supported by
this chronology. Otherwise, returns false .Checks if this chronology is ISO based. |
public boolean | Returns: true if the year is a leap yearthe proleptic-year to check, not validated for range prolepticYear)Checks if the specified year is a leap year. |
public default ChronoLocalDateTime | Returns: the local date-time in this chronology, not nullthe temporal object to convert, not null temporal)Obtains a local date-time in this chronology from another temporal object. |
public static Chronology | |
public static Chronology | |
public default ChronoPeriod | Returns: the period in terms of this chronology, not nullthe number of years, may be negative years, int the number of years, may be negative months, int the number of years, may be negative days)Obtains a period for this chronology based on years, months and days. |
public int | Returns: the proleptic-yearthe era of the correct type for the chronology, not null era, int the chronology year-of-era yearOfEra)Calculates the proleptic-year given the era and year-of-era. |
public ValueRange | Returns: the range of valid values for the field, not nullthe field to get the range for, not null field)Gets the range of valid values for the specified field. |
public ChronoLocalDate | Returns: the resolved date, null if insufficient information to create a datethe map of fields to values, which can be updated, not null fieldValues, ResolverStyle the requested type of resolve, not null resolverStyle)Resolves parsed |
public String | Returns: a string representation of this chronology, not nullOutputs this chronology as a |
public default ChronoZonedDateTime | Returns: the zoned date-time in this chronology, not nullthe temporal object to convert, not null temporal)Obtains a |
public default ChronoZonedDateTime | Returns: the zoned date-time, not nullthe instant to create the date-time from, not null instant, ZoneId the time-zone, not null zone)Obtains a |
compareTo | back to summary |
---|---|
public int compareTo(Chronology other) Redeclares java. Compares this chronology to another chronology.
The comparison order first by the chronology ID string, then by any
additional information specific to the subclass.
It is "consistent with equals", as defined by
|
date | back to summary |
---|---|
public default ChronoLocalDate date(Era era, int yearOfEra, int month, int dayOfMonth) Obtains a local date in this chronology from the era, year-of-era, month-of-year and day-of-month fields. Implementation Specification The default implementation combines the era and year-of-era into a proleptic
year before calling
|
date | back to summary |
---|---|
public ChronoLocalDate date(int prolepticYear, int month, int dayOfMonth) Obtains a local date in this chronology from the proleptic-year, month-of-year and day-of-month fields.
|
date | back to summary |
---|---|
public ChronoLocalDate date(TemporalAccessor temporal) Obtains a local date in this chronology from another temporal object.
This obtains a date in this chronology based on the specified temporal.
A
The conversion typically uses the
This method matches the signature of the functional interface
|
dateEpochDay | back to summary |
---|---|
public ChronoLocalDate dateEpochDay(long epochDay) Obtains a local date in this chronology from the epoch-day.
The definition of
|
dateNow | back to summary |
---|---|
public default ChronoLocalDate dateNow() Obtains the current local date in this chronology from the system clock in the default time-zone.
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded. Implementation Specification The default implementation invokes
|
dateNow | back to summary |
---|---|
public default ChronoLocalDate dateNow(ZoneId zone) Obtains the current local date in this chronology from the system clock in the specified time-zone.
This will query the Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded. Implementation Specification The default implementation invokes
|
dateNow | back to summary |
---|---|
public default ChronoLocalDate dateNow(Clock clock) Obtains the current local date in this chronology from the specified clock.
This will query the specified clock to obtain the current date - today.
Using this method allows the use of an alternate clock for testing.
The alternate clock may be introduced using Implementation Specification The default implementation invokes
|
dateYearDay | back to summary |
---|---|
public default ChronoLocalDate dateYearDay(Era era, int yearOfEra, int dayOfYear) Obtains a local date in this chronology from the era, year-of-era and day-of-year fields. Implementation Specification The default implementation combines the era and year-of-era into a proleptic
year before calling
|
dateYearDay | back to summary |
---|---|
public ChronoLocalDate dateYearDay(int prolepticYear, int dayOfYear) Obtains a local date in this chronology from the proleptic-year and day-of-year fields.
|
epochSecond | back to summary |
---|---|
public default long epochSecond(int prolepticYear, int month, int dayOfMonth, int hour, int minute, int second, ZoneOffset zoneOffset) Gets the number of seconds from the epoch of 1970-01-01T00:00:00Z. The number of seconds is calculated using the proleptic-year, month, day-of-month, hour, minute, second, and zoneOffset.
|
epochSecond | back to summary |
---|---|
public default long epochSecond(Era era, int yearOfEra, int month, int dayOfMonth, int hour, int minute, int second, ZoneOffset zoneOffset) Gets the number of seconds from the epoch of 1970-01-01T00:00:00Z. The number of seconds is calculated using the era, year-of-era, month, day-of-month, hour, minute, second, and zoneOffset.
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Checks if this chronology is equal to another chronology. The comparison is based on the entire state of the object. |
eraOf | back to summary |
---|---|
public Era eraOf(int eraValue) Creates the chronology era object from the numeric value. The era is, conceptually, the largest division of the time-line. Most calendar systems have a single epoch dividing the time-line into two eras. However, some have multiple eras, such as one for the reign of each leader. The exact meaning is determined by the chronology according to the following constraints. The era in use at 1970-01-01 must have the value 1. Later eras must have sequentially higher values. Earlier eras must have sequentially lower values. Each chronology must refer to an enum or similar singleton to provide the era values. This method returns the singleton era of the correct type for the specified era value.
|
eras | back to summary |
---|---|
public List Gets the list of eras for the chronology. Most calendar systems have an era, within which the year has meaning. If the calendar system does not support the concept of eras, an empty list must be returned. |
from | back to summary |
---|---|
public static Chronology from(TemporalAccessor temporal) Obtains an instance of
This obtains a chronology based on the specified temporal.
A
The conversion will obtain the chronology using
This method matches the signature of the functional interface
|
getAvailableChronologies | back to summary |
---|---|
public static Set Returns the available chronologies.
Each returned
|
getCalendarType | back to summary |
---|---|
public String getCalendarType() Gets the calendar type of the calendar system.
The calendar type is an identifier defined by the CLDR and
Unicode Locale Data Markup Language (LDML) specifications
to uniquely identify a calendar.
The |
getDisplayName | back to summary |
---|---|
public default String getDisplayName(TextStyle style, Locale locale) Gets the textual representation of this chronology. This returns the textual name used to identify the chronology, suitable for presentation to the user. The parameters control the style of the returned text and the locale. Implementation Specification The default implementation behaves as though the formatter was used to format the chronology textual name. |
getId | back to summary |
---|---|
public String getId() Gets the ID of the chronology.
The ID uniquely identifies the
|
hashCode | back to summary |
---|---|
public int hashCode() A hash code for this chronology. The hash code should be based on the entire state of the object.
|
isIsoBased | back to summary |
---|---|
public default boolean isIsoBased() Checks if this chronology is ISO based.
An ISO based chronology has the same basic structure as the Implementation Specification The default implementation returns
|
isLeapYear | back to summary |
---|---|
public boolean isLeapYear(long prolepticYear) Checks if the specified year is a leap year. A leap-year is a year of a longer length than normal. The exact meaning is determined by the chronology according to the following constraints.
Outside the range of valid years an implementation is free to return either a best guess or false. An implementation must not throw an exception, even if the year is outside the range of valid years.
|
localDateTime | back to summary |
---|---|
public default ChronoLocalDateTime Obtains a local date-time in this chronology from another temporal object.
This obtains a date-time in this chronology based on the specified temporal.
A
The conversion extracts and combines the
This method matches the signature of the functional interface
|
of | back to summary |
---|---|
public static Chronology of(String id) Obtains an instance of
This returns a chronology based on either the ID or the type.
The The chronology may be a system chronology or a chronology provided by the application via ServiceLoader configuration. Since some calendars can be customized, the ID or type typically refers to the default customization. For example, the Gregorian calendar can have multiple cutover dates from the Julian, but the lookup only provides the default cutover date.
|
ofLocale | back to summary |
---|---|
public static Chronology ofLocale(Locale locale) Obtains an instance of
This returns a
The
The
This method finds the desired calendar system in a manner equivalent
to passing "ca" to
Note that the behavior of this method differs from the older
A similar, but simpler, situation occurs for the Japanese calendar system.
The locale "jp_JP_JP" has previously been used to access the calendar.
However, unlike the Thai locale, "ja_JP_JP" is automatically converted by
|
period | back to summary |
---|---|
public default ChronoPeriod period(int years, int months, int days) Obtains a period for this chronology based on years, months and days.
This returns a period tied to this chronology using the specified
years, months and days. All supplied chronologies use periods
based on years, months and days, however the Implementation Specification The default implementation returns an implementation class suitable
for most calendar systems. It is based solely on the three units.
Normalization, addition and subtraction derive the number of months
in a year from the
If implementing an unusual calendar system that is not based on
years, months and days, or where you want direct control, then
the The returned period is immutable and thread-safe.
|
prolepticYear | back to summary |
---|---|
public int prolepticYear(Era era, int yearOfEra) Calculates the proleptic-year given the era and year-of-era. This combines the era and year-of-era into the single proleptic-year field.
If the chronology makes active use of eras, such as
|
range | back to summary |
---|---|
public ValueRange range(ChronoField field) Gets the range of valid values for the specified field.
All fields can be expressed as a Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field. This method will return a result whether or not the chronology supports the field.
|
resolveDate | back to summary |
---|---|
public ChronoLocalDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) Resolves parsed
Most
The default implementation, which explains typical resolve behaviour,
is provided in
|
toString | back to summary |
---|---|
public String toString() Outputs this chronology as a The format should include the entire state of the object. |
zonedDateTime | back to summary |
---|---|
public default ChronoZonedDateTime Obtains a
This obtains a zoned date-time in this chronology based on the specified temporal.
A
The conversion will first obtain a
This method matches the signature of the functional interface
|
zonedDateTime | back to summary |
---|---|
public default ChronoZonedDateTime Obtains a This obtains a zoned date-time with the same instant as that specified.
|