Access to date and time using fields and units, and date time adjusters.
This package expands on the base package to provide additional functionality for more powerful use cases. Support is included for:
- Units of date-time, such as years, months, days and hours
- Fields of date-time, such as month-of-year, day-of-week or hour-of-day
- Date-time adjustment functions
- Different definitions of weeks
Fields and Units
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
The set of well known units is defined in
ChronoUnit, such as
The unit interface is designed to allow application 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
The set of well known fields are defined in
ChronoField, such as
Additional fields are defined by
The field interface is designed to allow application 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
getDayOfMonth(). However for more unusual fields it is necessary to use the field.
The fields also provide access to the range of valid values.
Adjustment and Query
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
A set of common functions are provided in
For example, to find the first occurrence of a day-of-week after a given date, use
next(DayOfWeek), such as
Applications can also define adjusters by implementing
TemporalAmount interface models amounts of relative time.
In addition to adjusting a date-time, an interface is provided to enable querying via
The most common implementations of the query interface are method references.
from(TemporalAccessor) methods on major classes can all be used, such as
Further implementations are provided in
TemporalQueries as static methods.
Applications can also define queries by implementing
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.
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
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.
NullPointerException" is not explicitly documented in each method.
|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.|
|TemporalAdjuster||Strategy for adjusting a temporal object.|
|TemporalAmount||Framework-level interface defining an amount of time, such as "6 hours", "8 days" or "2 years and 3 months".|
|TemporalField||A field of date-time, such as month-of-year or hour-of-minute.|
|TemporalQuery<R>||Strategy for querying a temporal object.|
|TemporalUnit||A unit of date-time, such as Days or Hours.|
|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.|
|TemporalAdjusters||Common and useful TemporalAdjusters.|
Common implementations of
|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.|
|ChronoField||A standard set of fields.|
|ChronoUnit||A standard set of date periods units.|
|UnsupportedTemporalTypeException||UnsupportedTemporalTypeException indicates that a ChronoField or ChronoUnit is not supported for a Temporal class.|