Java Reference
In-Depth Information
Table 12-5. List of Predefined Datetime Formatters
Formatter
Description
Example
BASIC_ISO_DATE
20140109, 20140109-0600
An ISO date formatter to format and parse
a date without using a separator between
two date components.
ISO_DATE,
ISO_TIME, ISO_DATE_TIME
2014-01-09, 2014-01-09-06:00,
15:38:32.927, 15:38:32.943-06:00,
2014-01-09T15:20:07.747-06:00,
2014-01-09T15:20:07.825-
06:00[America/Chicago]
Date, time, and datetime formatters
to format and parse dates, times, and
datetimes using the ISO separators.
ISO_INSTANT
2014-01-09T21:23:56.870Z
An instant formatter to format and
parse an instant (or a datetime object
representing an instant such as a
ZonedDateTime ) in UTC format.
ISO_LOCAL_DATE,
ISO_LOCAL_TIME,
ISO_LOCAL_DATE_TIME
2014-01-09, 15:30:14.352,
2014-01-09T15:29:11.384
Date, time, and datetime formatters
to format or parse dates, times, and
datetimes without an offset.
ISO_OFFSET_DATE,
ISO_OFFSET_TIME,
ISO_OFFSET_DATE_TIME
2014-01-09-06:00,
15:34:29.851-06:00,
2014-01-09T15:33:07.07-06:0
Date, time, and datetime formatters
to format and parse dates, times, and
datetimes with an offset using ISO format.
ISO_ZONED_DATE_TIME
2014-01-09T15:45:49.112-06:00,
2014-01-09T15:45:49.128-
06:00[America/Chicago]
A datetime formatter to format and parse a
datetime with a zone id, if available.
ISO_ORDINAL_DATE
2014-009
A date formatter to format and parse a
date with year and day-of-year.
ISO_WEEK_DATE
2014-W02-4,
2014-W02-4-06:00
A date formatter to format and parse week-
based dates. The format is year-Wweek_
of_year-day_of_week. For example,
'2014-W02-4' means the fourth day of the
second week in 2014.
RFC_1123_DATE_TIME
Thu, 9 Jan 2014 15:50:44 -060
A datetime formatter to format and parse
datetimes for e-mails using the RFC1123
specification.
Using the predefined formatters is easy: just pass the date/time object to the format() . The following snippet of
code uses ISO_DATE formatter to format a LocalDate , an OffsetDateTime , and ZonedDateTime . You may get a different
output as it formats and prints the current date.
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
import static java.time.format.DateTimeFormatter.ISO_DATE;
...
 
Search WWH ::




Custom Search