Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class DateTimeFormatter
- Object
- DateTimeFormatter
Formats and parses dates and times: the ISO formats as constants, and
any other through ofPattern(String).
Patterns follow the JDK’s letters and counts. Supported: G era, u
year, y year of era, M/L month, d day of month, D day of
year, Q/q quarter, E day of week, a AM/PM, h, K, k, H
hours, m minutes, s seconds, S fraction of a second, n nano of
second, N nano of day, A milli of day, VV zone id, z (the zone
id), O, X, x and Z offsets, quoted text, and [...] optional
sections. Text is English whatever the locale. The week-based letters
(Y, w, W, e, c, F, g), v, B and p are refused.
A pattern parses as the JDK’s smart resolver does: a day of month past the end of its month becomes the last day, an hour alone is that hour on the dot, and a two-digit year is one of 2000 to 2099. The ISO formats resolve strictly.
Fields
Methods
Inherited methods
Field details
ISO_LOCAL_DATE
public static final DateTimeFormatter ISO_LOCAL_DATEISO_LOCAL_TIME
public static final DateTimeFormatter ISO_LOCAL_TIMEISO_LOCAL_DATE_TIME
public static final DateTimeFormatter ISO_LOCAL_DATE_TIMEISO_OFFSET_DATE_TIME
public static final DateTimeFormatter ISO_OFFSET_DATE_TIMEISO_ZONED_DATE_TIME
public static final DateTimeFormatter ISO_ZONED_DATE_TIMEISO_INSTANT
public static final DateTimeFormatter ISO_INSTANTMethod details
ofPattern
public static DateTimeFormatter ofPattern(String pattern)ofPattern
public static DateTimeFormatter ofPattern(String pattern, Locale locale)withZone
public DateTimeFormatter withZone(ZoneId zone)zone overriding the zone of what it formats and
supplying one to what it parses; null removes the override.getZone
public ZoneId getZone()withZone(ZoneId), or null.withLocale
public DateTimeFormatter withLocale(Locale locale)getLocale
public Locale getLocale()format
public String format(TemporalAccessor temporal)parse
public TemporalAccessor parse(CharSequence text)parse
public <T> T parse(CharSequence text, TemporalQuery<T> query)text and hands the result to query, as in
formatter.parse(text, LocalDate::from).toString
public String toString()