Constructor.
Formats a date-time object using this formatter. !(p) This formats the date-time to a string using the rules of the formatter.
Formats a date-time object to an {@code Appendable} using this formatter. !(p) This outputs the formatted date-time to the specified destination. {@link Appendable} is a general purpose interface that is implemented by all key character output classes including {@code StringBuffer}, {@code StringBuilder}, {@code PrintStream} and {@code Writer}. !(p) Although {@code Appendable} methods throw an {@code IOException}, this method does not. Instead, any {@code IOException} is wrapped _in a runtime exception.
Gets the overriding chronology to be used during formatting. !(p) This returns the override chronology, used to convert dates. By default, a formatter has no override chronology, returning null. See {@link #withChronology(Chronology)} for more details on overriding.
Gets the DecimalStyle to be used during formatting.
Gets the locale to be used during formatting. !(p) This is used to lookup any part of the formatter needing specific localization, such as the text or localized pattern.
Gets the resolver fields to use during parsing. !(p) This returns the resolver fields, used during the second phase of parsing when fields are resolved into dates and times. By default, a formatter has no resolver fields, and thus returns null. See {@link #withResolverFields(Set)} for more details.
Gets the resolver style to use during parsing. !(p) This returns the resolver style, used during the second phase of parsing when fields are resolved into dates and times. By default, a formatter has the {@link ResolverStyle#SMART SMART} resolver style. See {@link #withResolverStyle(ResolverStyle)} for more details.
Gets the overriding zone to be used during formatting. !(p) This returns the override zone, used to convert instants. By default, a formatter has no override zone, returning null. See {@link #withZone(ZoneId)} for more details on overriding.
Fully parses the text producing a temporal object. !(p) This parses the entire text producing a temporal object. It is typically more useful to use {@link #parse(string, TemporalQuery)}. The result of this method is {@code TemporalAccessor} which has been resolved, applying basic validation checks to help ensure a valid date-time. !(p) If the parse completes without reading the entire length of the text, or a problem occurs during parsing or merging, then an exception is thrown.
Parses the text using this formatter, providing control over the text position. !(p) This parses the text without requiring the parse to start from the beginning of the string or finish at the end. The result of this method is {@code TemporalAccessor} which has been resolved, applying basic validation checks to help ensure a valid date-time. !(p) The text will be parsed from the specified start {@code ParsePosition}. The entire length of the text does not have to be parsed, the {@code ParsePosition} will be updated with the index at the end of parsing. !(p) The operation of this method is slightly different to similar methods using {@code ParsePosition} on {@code java.text.Format}. That class will return errors using the error index on the {@code ParsePosition}. By contrast, this method will throw a {@link DateTimeParseException} if an error occurs, with the exception containing the error index. This change _in behavior is necessary due to the increased complexity of parsing and resolving dates/times _in this API. !(p) If the formatter parses the same field more than once with different values, the result will be an error.
Fully parses the text producing an object of the specified type. !(p) Most applications should use this method for parsing. It parses the entire text to produce the required date-time. The query is typically a method reference to a {@code from(TemporalAccessor)} method. For example: !(pre) LocalDateTime dt = parser.parse(str, LocalDateTime.from); </pre> If the parse completes without reading the entire length of the text, or a problem occurs during parsing or merging, then an exception is thrown.
Fully parses the text producing an object of one of the specified types. !(p) This parse method is convenient for use when the parser can handle optional elements. For example, a pattern of 'uuuu-MM-dd HH.mm[ VV]' can be fully parsed to a {@code ZonedDateTime}, or partially parsed to a {@code LocalDateTime}. The queries must be specified _in order, starting from the best matching full-parse option and ending with the worst matching minimal parse option. The query is typically a method reference to a {@code from(TemporalAccessor)} method. !(p) The result is associated with the first type that successfully parses. Normally, applications will use {@code instanceof} to check the result. For example: !(pre) TemporalAccessor dt = parser.parseBest(str, ZonedDateTime::from, LocalDateTime.from); if (cast(ZonedDateTime)(dt) !is null) { ... } else { ... } </pre> If the parse completes without reading the entire length of the text, or a problem occurs during parsing or merging, then an exception is thrown.
Parses the text using this formatter, without resolving the result, intended for advanced use cases. !(p) Parsing is implemented as a two-phase operation. First, the text is parsed using the layout defined by the formatter, producing a {@code Map} of field to value, a {@code ZoneId} and a {@code Chronology}. Second, the parsed data is !(em)resolved</em>, by validating, combining and simplifying the various fields into more useful ones. This method performs the parsing stage but not the resolving stage. !(p) The result of this method is {@code TemporalAccessor} which represents the data as seen _in the input. Values are not validated, thus parsing a date string of '2012-00-65' would result _in a temporal with three fields - year of '2012', month of '0' and day-of-month of '65'. !(p) The text will be parsed from the specified start {@code ParsePosition}. The entire length of the text does not have to be parsed, the {@code ParsePosition} will be updated with the index at the end of parsing. !(p) Errors are returned using the error index field of the {@code ParsePosition} instead of {@code DateTimeParseException}. The returned error index will be set to an index indicative of the error. Callers must check for errors before using the result. !(p) If the formatter parses the same field more than once with different values, the result will be an error. !(p) This method is intended for advanced use cases that need access to the internal state during parsing. Typical application code should use {@link #parse(string, TemporalQuery)} or the parse method on the target type.
Returns the formatter as a composite printer parser.
Returns a description of the underlying formatters.
Returns a copy of this formatter with a new override chronology. !(p) This returns a formatter with similar state to this formatter but with the override chronology set. By default, a formatter has no override chronology, returning null. !(p) If an override is added, then any date that is formatted or parsed will be affected. !(p) When formatting, if the temporal object contains a date, then it will be converted to a date _in the override chronology. Whether the temporal contains a date is determined by querying the {@link ChronoField#EPOCH_DAY EPOCH_DAY} field. Any time or zone will be retained unaltered unless overridden. !(p) If the temporal object does not contain a date, but does contain one or more {@code ChronoField} date fields, then a {@code DateTimeException} is thrown. In all other cases, the override chronology is added to the temporal, replacing any previous chronology, but without changing the date/time. !(p) When parsing, there are two distinct cases to consider. If a chronology has been parsed directly from the text, perhaps because {@link DateTimeFormatterBuilder#appendChronologyId()} was used, then this override chronology has no effect. If no zone has been parsed, then this override chronology will be used to interpret the {@code ChronoField} values into a date according to the date resolving rules of the chronology. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this formatter with a new DecimalStyle. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this formatter with a new locale. !(p) This is used to lookup any part of the formatter needing specific localization, such as the text or localized pattern. !(p) The locale is stored as passed _in, without further processing. If the locale has <a href="../../util/Locale.html#def_locale_extension"> Unicode extensions</a>, they may be used later _in text processing. To set the chronology, time-zone and decimal style from unicode extensions, see {@link #localizedBy localizedBy()}. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this formatter with a new resolver style. !(p) This returns a formatter with similar state to this formatter but with the resolver style set. By default, a formatter has the {@link ResolverStyle#SMART SMART} resolver style. !(p) Changing the resolver style only has an effect during parsing. Parsing a text string occurs _in two phases. Phase 1 is a basic text parse according to the fields added to the builder. Phase 2 resolves the parsed field-value pairs into date and/or time objects. The resolver style is used to control how phase 2, resolving, happens. See {@code ResolverStyle} for more information on the options available. !(p) This instance is immutable and unaffected by this method call.
Returns a copy of this formatter with a new override zone. !(p) This returns a formatter with similar state to this formatter but with the override zone set. By default, a formatter has no override zone, returning null. !(p) If an override is added, then any instant that is formatted or parsed will be affected. !(p) When formatting, if the temporal object contains an instant, then it will be converted to a zoned date-time using the override zone. Whether the temporal is an instant is determined by querying the {@link ChronoField#INSTANT_SECONDS INSTANT_SECONDS} field. If the input has a chronology then it will be retained unless overridden. If the input does not have a chronology, such as {@code Instant}, then the ISO chronology will be used. !(p) If the temporal object does not contain an instant, but does contain an offset then an additional check is made. If the normalized override zone is an offset that differs from the offset of the temporal, then a {@code DateTimeException} is thrown. In all other cases, the override zone is added to the temporal, replacing any previous zone, but without changing the date/time. !(p) When parsing, there are two distinct cases to consider. If a zone has been parsed directly from the text, perhaps because {@link DateTimeFormatterBuilder#appendZoneId()} was used, then this override zone has no effect. If no zone has been parsed, then this override zone will be included _in the result of the parse where it can be used to build instants and date-times. !(p) This instance is immutable and unaffected by this method call.
A query that provides access to the excess days that were parsed. !(p) This returns a singleton {@linkplain TemporalQuery query} that provides access to additional information from the parse. The query always returns a non-null period, with a zero period returned instead of null. !(p) There are two situations where this query may return a non-zero period. !(ul) !(li)If the {@code ResolverStyle} is {@code LENIENT} and a time is parsed without a date, then the complete result of the parse consists of a {@code LocalTime} and an excess {@code Period} _in days.
A query that provides access to whether a leap-second was parsed. !(p) This returns a singleton {@linkplain TemporalQuery query} that provides access to additional information from the parse. The query always returns a non-null bool, true if parsing saw a leap-second, false if not. !(p) Instant parsing handles the special "leap second" time of '23:59:60'. Leap seconds occur at '23:59:60' _in the UTC time-zone, but at other local times _in different time-zones. To avoid this potential ambiguity, the handling of leap-seconds is limited to {@link DateTimeFormatterBuilder#appendInstant()}, as that method always parses the instant with the UTC zone offset. !(p) If the time '23:59:60' is received, then a simple conversion is applied, replacing the second-of-minute of 60 with 59. This query can be used on the parse result to determine if the leap-second adjustment was made. The query will return {@code true} if it did adjust to remove the leap-second, and {@code false} if not. Note that applying a leap-second smoothing mechanism, such as UTC-SLS, is the responsibility of the application, as follows: !(pre) TemporalAccessor parsed = formatter.parse(str); Instant instant = parsed.query(Instant::from); if (parsed.query(DateTimeFormatter.parsedLeapSecond())) { // validate leap-second is correct and apply correct smoothing } </pre> @return a query that provides access to whether a leap-second was parsed