Class 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatterstatic final DateTimeFormatter -
Method Summary
Modifier and TypeMethodDescriptionformat(TemporalAccessor temporal) getZone()The zone given towithZone(ZoneId), or null.static DateTimeFormatterstatic DateTimeFormatterparse(CharSequence text) <T> Tparse(CharSequence text, TemporalQuery<T> query) Parsestextand hands the result toquery, as informatter.parse(text, LocalDate::from).toString()Returns a string representation of the object.withLocale(Locale locale) This formatter withzoneoverriding the zone of what it formats and supplying one to what it parses; null removes the override.
-
Field Details
-
ISO_LOCAL_DATE
-
ISO_LOCAL_TIME
-
ISO_LOCAL_DATE_TIME
-
ISO_OFFSET_DATE_TIME
-
ISO_ZONED_DATE_TIME
-
ISO_INSTANT
-
-
Method Details
-
ofPattern
-
ofPattern
-
withZone
This formatter withzoneoverriding the zone of what it formats and supplying one to what it parses; null removes the override. -
getZone
The zone given towithZone(ZoneId), or null. -
withLocale
-
getLocale
-
format
-
parse
-
parse
Parsestextand hands the result toquery, as informatter.parse(text, LocalDate::from). -
toString
Description copied from class:ObjectReturns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
-