Class DateFormats
NumberFormats: what a table puts in a date
column, and what any caption that shows a day or an hour can use.
Every format here follows the language in effect where it
formats, read at that moment, as NumberFormats' do: the order of day, month and year,
the separators and a month's name are the language's, and a widget inside a subtree that
declares its own locale formats in that subtree's language. The digits are the toolkit's,
the numbering system's, as every number it writes: the
platform writes a date in ASCII digits whatever the language, so under ar-EG a date
beside an amount read 17/10/2026 next to ١٬٢٣٤٫٥, where these write
١٧/١٠/٢٠٢٦.
Column.of("Due", Order::due, DateFormats.date(FormatStyle.SHORT)); // "10/17/26", "17/10/2026"
label.setText(DateFormats.time(FormatStyle.SHORT).apply(at)); // "2:09 PM", "14:09"
The calendar is the locale's. A locale that names a calendar system with the Unicode
extension -u-ca-, as a user's settings write a choice of calendar, is written in it, as
the date widgets draw it: ja-JP-u-ca-japanese writes the era ("R7/10/25"),
th-TH-u-ca-buddhist the Buddhist year (2568), ar-SA-u-ca-islamic-umalqura the
Hijri date. The value is the same LocalDate either way; only how it is written changes.
A calendar the platform does not carry is read as none, and a locale that names none is written
in the ISO calendar, which is what the platform answers for every language without one. A day
the named calendar does not reach is written in the ISO calendar too, as the date widgets draw
it: the platform's Umm al-Qura calendar covers 1882 to 2174 and its Japanese one nothing before
1873, so a 9999-12-31 that stands for "no end date" is written under
ar-SA-u-ca-islamic-umalqura as the ISO date it is, where the platform refuses it. That
holds for every style, and for the date in a date and time, and the time of day alone of one.
A format takes any temporal that holds the fields it writes: a LocalDate for a date,
a LocalTime for a time, a LocalDateTime for both, and a zoned or offset one for
any of them. One that lacks a field the format writes is refused by the platform with a
DateTimeException.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Function<TemporalAccessor, String> date(FormatStyle style) A date atstyle's length:SHORTwrites10/17/26in English and17/10/2026in Brazilian Portuguese,MEDIUMwritesOct 17, 2026, andLONGandFULLwrite the month, and the weekday, in words.static Function<TemporalAccessor, String> dateTime(FormatStyle style) A date and a time of day, both atstyle's length:SHORTwrites10/17/26, 2:09 PMin English and17/10/2026, 14:09in Brazilian Portuguese.static Function<TemporalAccessor, String> time(FormatStyle style) A time of day atstyle's length:SHORTwrites2:09 PMin English and14:09in Brazilian Portuguese,MEDIUMadds the seconds.
-
Method Details
-
date
A date atstyle's length:SHORTwrites10/17/26in English and17/10/2026in Brazilian Portuguese,MEDIUMwritesOct 17, 2026, andLONGandFULLwrite the month, and the weekday, in words.- Parameters:
style- how long the date is written; nevernull- Returns:
- the format
-
time
A time of day atstyle's length:SHORTwrites2:09 PMin English and14:09in Brazilian Portuguese,MEDIUMadds the seconds.- Parameters:
style-SHORTorMEDIUM; nevernull- Returns:
- the format
- Throws:
IllegalArgumentException- forLONGorFULL, which write a time zone that a time of day does not have, and which the platform would refuse only when the first value was formatted
-
dateTime
A date and a time of day, both atstyle's length:SHORTwrites10/17/26, 2:09 PMin English and17/10/2026, 14:09in Brazilian Portuguese.- Parameters:
style-SHORTorMEDIUM; nevernull- Returns:
- the format
- Throws:
IllegalArgumentException- forLONGorFULL, astime(java.time.format.FormatStyle)does
-