What Is Date-Time API
This section provides introductions on what the Date-Time API introduced in Java 8 (JDK 1.8). The Date-Time API is replacing the java.util.Date class and the java.util.GregorianCalendar class.
What Is Date-Time API?
The Date-Time API (Application Programming Interface) is a new API introduced in Java 8 (JDK 1.8)
to manage time and date. The Date-Time API is a replacement of the current
java.util.Date, java.util.GregorianCalendar, and java.util.SimpleTimeZone classes.
The Date-Time API is represented with the following packages:
- java.time.* -
The core of the API for representing date and time. It includes classes for date, time, date and time combined, time zones, instants, duration, and clocks. These classes are based on the calendar system defined in ISO-8601, and are immutable and thread-safe.
- java.time.chrono.* -
The API for representing calendar systems other than the default ISO-8601. You can also define your own calendar system. This tutorial does not cover this package in any detail.
- java.time.format.* -
Classes for formatting and parsing dates and times.
- java.time.temporal.* -
Extended API, primarily for framework and library writers, allowing interoperations between the date and time classes,
querying, and adjustment. Fields (TemporalField and ChronoField) and units (TemporalUnit and ChronoUnit) are defined in this package.
- java.time.zone.* -
Classes that support timezones, UTC offsets from timezones, and timezone rules. If working with timezones,
most developers will need to use only ZonedDateTime, and ZoneId or ZoneOffset.
The core package of the Date-Time API is the java.time.* package, which provides the following main classes:
- java.time.Instant - Represents an instantaneous moment of time expressed in Epoch seconds and a fraction,
or the number seconds and the fraction passed between the moment of time and the Unix Epoch (1970-01-01T00:00:00Z) reference point.
A java.time.Instant object does not record any calendar date information, but when print it into a string,
it maps the moment of time into a date and time in the ISO 8601 calendar in UTC time zone
and showing the moment of time in the format like "2014-04-01T04:41:10.123456789Z".
This may give you a false impression that java.time.Instant class can be used to manage calendar date information.
- java.time.ZonedDateTime - Represents a moment of time expressed in date and time fields of a specific timezone
in the ICO 8601 calendar. It offers date and time manipulation methods that respects ISO 8601 calendar rules and
daylight saving time timezone rules.
- java.time.OffsetDateTime - Represents a moment of time expressed in date and time fields of a specific UTC offset
in the ICO 8601 calendar. It offers date and time manipulation methods that respects ISO 8601 calendar rules.
- java.time.Period - Represents an approximate amount of time in ISO calendar years, months and/or days.
The actual amount of time represented by a java.time.Period object is based on how the object is being used.
For example, when adding a 1-month java.time.Period object to March 1, it represents 31 days.
When adding it to April 1, it represents only 30 days.
- java.time.Duration - Represents an precise amount of time in seconds and a fraction (in nanoseconds) of a second.
Last update: 2014.
Table of Contents
About This JDK Tutorial Book
JDK (Java Development Kit)
►Java Date-Time API
►What Is Date-Time API
java.time.Instant - Representing a Moment of Time
java.time.Instant Usage Examples
java.time.Instant - get(INSTANT_SECONDS) Error
Converting java.util.Date to java.time.Instant
java.time.ZonedDateTime - Calendar and Timezone
java.time.ZonedDateTime Usage Examples
Converting java.util.GregorianCalendar to java.time.ZonedDateTime
java.time.OffsetDateTime - Calendar and UTC Offset
java.time.OffsetDateTime Usage Examples
java.time.LocalDateTime - Local Date and time without Timezone
Partial Date and Time Objects and Classes
java.time.format.DateTimeFormatter - Date-Time Strings
java.time.Duration - Time Durations
java.time.Duration Usage Examples
java.time.Period - Periods in Days and Months
java.time.Period Usage Examples
Date, Time and Calendar Classes
Date and Time Object and String Conversion
Number Object and Numeric String Conversion
Locales, Localization Methods and Resource Bundles
Calling and Importing Classes Defined in Unnamed Packages
HashSet, Vector, HashMap and Collection Classes
Character Set Encoding Classes and Methods
Character Set Encoding Maps
Encoding Conversion Programs for Encoded Text Files
Socket Network Communication
Datagram Network Communication
DOM (Document Object Model) - API for XML Files
SAX (Simple API for XML)
DTD (Document Type Definition) - XML Validation
XSD (XML Schema Definition) - XML Validation
XSL (Extensible Stylesheet Language)
Message Digest Algorithm Implementations in JDK
Private key and Public Key Pair Generation
PKCS#8/X.509 Private/Public Encoding Standards
Digital Signature Algorithm and Sample Program
"keytool" Commands and "keystore" Files
KeyStore and Certificate Classes
Secret Key Generation and Management
Cipher - Encryption and Decryption
The SSL (Secure Socket Layer) Protocol
SSL Socket Communication Testing Programs
SSL Client Authentication
HTTPS (Hypertext Transfer Protocol Secure)
Full Version in PDF/EPUB