Formatter for printing and parsing date-time objects.
This class provides the main application entry point for printing and parsing. Common instances of {@code DateTimeFormatter} are provided:
- Using pattern letters, such as {@code yyyy-MMM-dd}
- Using localized styles, such as {@code long} or {@code medium}
- Using predefined constants, such as {@link #ISO_LOCAL_DATE}
For more complex formatters, a {@link DateTimeFormatterBuilder builder} is provided.
In most cases, it is not necessary to use this class directly when formatting. The main date-time classes provide two methods - one for formatting, {@code format(DateTimeFormatter formatter)}, and one for parsing, For example:
String text = date.format(formatter); LocalDate date = LocalDate.parse(text, formatter);
Some aspects of printing and parsing are dependent on the locale. The locale can be changed using the {@link #withLocale(Locale)} methodwhich returns a new formatter in the requested locale.
Some applications may need to use the older {@link Format} class for formatting.The {@link #toFormat()} method returns an implementation of the old API.
Specification for implementors
This class is immutable and thread-safe.