JDK Tutorials - Herong's Tutorial Examples
∟Java Date-Time API
∟java.time.OffsetDateTime - Calendar and UTC Offset
This section describes the java.time.OffsetDateTime class that represents a local time in a specific UTC offset expressed in 3 components, ISO 8601 date, time of day and UTC offset.
java.time.OffsetDateTime is the third class of the Date-Time API introduced in JDK 1.8
that can be used to represent a moment of time.
A java.time.OffsetDateTime object represents a time with 3 components:
- UTC offset - Representing an offset against the UTC time.
This component can be expressed as hours and minutes like "+01:00".
- Local-Date - Representing a date in ISO 8601 calendar adjusted by the UTC offset.
This component can be expressed as a year, month, and day combination like "2014-04-01".
- Local-Time - Representing a time of the day adjusted by the UTC offset.
This component can be expressed as a hour, minute, second and fraction of second combination like
"07:48:41.750123456".
The java.time.OffsetDateTime class is designed mainly for manipulating local times
and pass them across different timezones.
Main methods offered on the java.time.Instant class are:
- of() - A static method returning a OffsetDateTime object representing a local time
constructed by a given ISO 8601 date, time of day and UTC offset.
- ofInstant() - A static method returning a OffsetDateTime object representing the local time
converted from a given Instant object and a given UTC offset.
- getYear() - An object method returning the year value of this OffsetDateTime object.
- getMonthValue() - An object method returning the month-of-year value of this OffsetDateTime object.
- getDayOfMonth() - An object method returning the day-of-month value of this OffsetDateTime object.
- getDayOfWeek() - An object method returning the day-of-week value of this OffsetDateTime object.
- getHour() - An object method returning the hour-of-day value of this OffsetDateTime object.
- getMinute() - An object method returning the minute-of-hour value of this OffsetDateTime object.
- getSecond() - An object method returning the second-of-minute value of this OffsetDateTime object.
- getNano() - An object method returning the Nanosecond-of-Second value of this OffsetDateTime object.
- getOffset() - An object method returning the UTC offset information of this ZonedDateTime object.
- get() - An object method returning the value of a given temporal field,
NANO_OF_SECOND, SECOND_OF_MINUTE, MINUTE_OF_HOUR, HOUR_OF_DAY, DAY_OF_WEEK, DAY_OF_MONTH, MONTH_OF_YEAR, YEAR, INSTANT_SECONDS, OFFSET_SECONDS, etc.
from this OffsetDateTime object.
- toString() - An object method returning a string representing this OffsetDateTime object in ISO 8601 date and time format.
Here is an example of toString() output, "2014-04-01T04:41:10.123456789+01:00".
- plus() - An object method returns a copy of this OffsetDateTime object with additional date or time units added.
During the operation, ISO 8601 calendar rules are respected.
- minus() - An object method returns a copy of this OffsetDateTime object with additional date or time units removed.
During the operation, ISO 8601 calendar rules are respected.
- with() - An object method returns a copy of this OffsetDateTime object with a new value set on a specified field
and other fields adjusted accordingly.
During the operation, ISO 8601 calendar rules are respected.
- parse() - A static method returning a OffsetDateTime object representing a moment of time constructed by
parsing the given character sequence using the ISO 8601 date and time format like
"2007-12-03T10:15:30+01:00.123+01:00"
- now() - A static method returning a OffsetDateTime object representing the local time based on the system clock time.
and the local UTC offset.
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
Java Logging
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)
Outdated Tutorials
References
Full Version in PDF/EPUB