See: Description
Interface | Description |
---|---|
ChronoLocalDate<C extends Chrono<C>> |
A date without time-of-day or time-zone in an arbitrary chronology, intended
for advanced globalization use cases.
|
ChronoLocalDateTime<C extends Chrono<C>> |
A date-time without a time-zone in an arbitrary chronology, intended
for advanced globalization use cases.
|
ChronoZonedDateTime<C extends Chrono<C>> |
A date-time with a time-zone in an arbitrary chronology,
intended for advanced globalization use cases.
|
Era<C extends Chrono<C>> |
An era of the time-line.
|
Temporal |
Framework-level interface defining read-write access to a temporal object,
such as a date, time, offset or some combination of these.
|
TemporalAccessor |
Framework-level interface defining read-only access to a temporal object,
such as a date, time, offset or some combination of these.
|
TemporalAdder |
Strategy for adding to a temporal object.
|
TemporalAdjuster |
Strategy for adjusting a temporal object.
|
TemporalField |
A field of date-time, such as month-of-year or hour-of-minute.
|
TemporalQuery<R> |
Strategy for querying a temporal object.
|
TemporalSubtractor |
Strategy for subtracting from a temporal object.
|
TemporalUnit |
A unit of date-time, such as Days or Hours.
|
Class | Description |
---|---|
Adjusters |
Common implementations of
TemporalAdjuster . |
Chrono<C extends Chrono<C>> |
A calendar system, used to organize and identify dates.
|
ISOChrono |
The ISO calendar system.
|
ISOFields |
Fields and units specific to the ISO-8601 calendar system,
including quarter-of-year and week-based-year.
|
JulianFields |
A set of date fields that provide access to Julian Days.
|
MonthDay |
A month-day in the ISO-8601 calendar system, such as
--12-03 . |
OffsetDate |
A date with an offset from UTC/Greenwich in the ISO-8601 calendar system,
such as
2007-12-03+01:00 . |
OffsetDateTime |
A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
such as
2007-12-03T10:15:30+01:00 . |
OffsetTime |
A time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
such as
10:15:30+01:00 . |
Queries |
Common implementations of
TemporalQuery . |
SimplePeriod |
A period of time, measured as an amount of a single unit, such as '3 Months'.
|
ValueRange |
The range of valid values for a date-time field.
|
WeekFields |
Localized definitions of the day-of-week, week-of-month and week-of-year fields.
|
Year |
A year in the ISO-8601 calendar system, such as
2007 . |
YearMonth |
A year-month in the ISO-8601 calendar system, such as
2007-12 . |
Enum | Description |
---|---|
ChronoField |
A standard set of fields.
|
ChronoUnit |
A standard set of date periods units.
|
Access to date and time using fields and units, additional value type classes and base support for calendar systems other than the default ISO.
This package expands on the base package to provide additional functionality for more powerful use cases. Support is included for:
Dates and times are expressed in terms of fields and units.
A unit is used to measure an amount of time, such as years, days or minutes.
All units implement TemporalUnit
.
The set of well known units is defined in ChronoUnit
, such as DAYS
.
The unit interface is designed to allow applications defined units.
A field is used to express part of a larger date-time, such as year, month-of-year or second-of-minute.
All fields implement TemporalField
.
The set of well known fields are defined in ChronoField
, such as HOUR_OF_DAY
.
Additional fields are defined by JulianFields
, WeekFields
and ISOFields
.
The field interface is designed to allow applications defined fields.
This package provides tools that allow the units and fields of date and time to be accessed
in a general way most suited for frameworks.
Temporal
provides the abstraction for date time types that support fields.
Its methods support getting the value of a field, creating a new date time with the value of
a field modified, and querying for additional information, typically used to extract the offset or time-zone.
One use of fields in application code is to retrieve fields for which there is no convenience method.
For example, getting the day-of-month is common enough that there is a method on LocalDate
called getDayOfMonth()
. However for more unusual fields it is necessary to use the field.
For example, date.get(ChronoField.ALIGNED_WEEK_OF_MONTH)
.
The fields also provide access to the range of valid values.
A key part of the date-time problem space is adjusting a date to a new, related value,
such as the "last day of the month", or "next Wednesday".
These are modeled as functions that adjust a base date-time.
The functions implement TemporalAdjuster
and operate on Temporal
.
A set of common functions are provided in Adjusters
.
For example, to find the first occurrence of a day-of-week after a given date, use
Adjusters.next(DayOfWeek)
, such as
date.with(next(MONDAY))
.
Applications can also define adjusters by implementing TemporalAdjuster
.
There are additional interfaces to model addition to and subtraction from a date-time.
These are TemporalAdder
and TemporalSubtractor
.
In addition to adjusting a date-time, an interface is provided to enable querying -
TemporalQuery
.
The most common implementations of the query interface are method references.
The from(TemporalAccessor)
methods on major classes can all be used, such as
LocalDate::from
or Month::from
.
Further implementations are provided in Queries
.
Applications can also define queries by implementing TemporalQuery
.
Different locales have different definitions of the week.
For example, in Europe the week typically starts on a Monday, while in the US it starts on a Sunday.
The WeekFields
class models this distinction.
The ISO calendar system defines an additional week-based division of years.
This defines a year based on whole Monday to Monday weeks.
This is modeled in ISOFields
.
The main API is based around the calendar system defined in ISO-8601.
However, there are other calendar systems, and this package provides basic support for them.
The alternate calendars are provided in the java.time.calendar
package.
A calendar system is defined by the Chrono
interface,
while a date in a calendar system is defined by the ChronoLocalDate
interface.
It is intended that applications use the main API whenever possible, including code to read and write from a persistent data store, such as a database, and to send dates and times across a network. The "chrono" classes are then used at the user interface level to deal with localized input/output.
Using non-ISO calendar systems in an application introduces significant extra complexity.
Ensure that the warnings and recommendations in ChronoLocalDate
have been read before
working with the "chrono" interfaces.
This example creates and uses a date in a non-ISO calendar system.
// Print the Thai Buddhist date ChronoLocalDate<ThaiBuddhistChrono> now1 = ThaiBuddhistChrono.INSTANCE.dateNow(); int day = now1.get(ChronoField.DAY_OF_MONTH); int dow = now1.get(ChronoField.DAY_OF_WEEK); int month = now1.get(ChronoField.MONTH_OF_YEAR); int year = now1.get(ChronoField.YEAR); System.out.printf(" Today is %s %s %d-%s-%d%n", now1.getChrono().getId(), dow, day, month, year); // Enumerate the list of available calendars and print today for each Set<Chrono<?>> chronos = Chrono.getAvailableChronologies(); for (Chrono<?> chrono : chronos) { ChronoLocalDate<?> date = chrono.dateNow(); System.out.printf(" %20s: %s%n", chrono.getId(), date.toString()); } // Print today's date and the last day of the year for the Thai Buddhist Calendar. ChronoLocalDate<ThaiBuddhistChrono> first = now1 .with(ChronoField.DAY_OF_MONTH, 1) .with(ChronoField.MONTH_OF_YEAR, 1); ChronoLocalDate<ThaiBuddhistChrono> last = first .plus(1, ChronoUnit.YEARS) .minus(1, ChronoUnit.DAYS); System.out.printf(" %s: 1st of year: %s; end of year: %s%n", last.getChrono().getId(), first, last);
Unless otherwise noted, passing a null argument to a constructor or method in any class or interface
in this package will cause a NullPointerException
to be thrown.
The Javadoc "@param" definition is used to summarise the null-behavior.
The "@throws NullPointerException
" is not explicitly documented in each method.
All calculations should check for numeric overflow and throw either an ArithmeticException
or a DateTimeException
.