Localized Formats Render Per Locale
Render dates with ofLocalizedDate and FormatStyle, where the pattern itself comes from the formatter locale and FULL/LONG need a zone on the temporal.
Code
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.Locale;
public class InvoiceDate {
public static void main(String[] args) {
LocalDate billed = LocalDate.of(2026, 11, 23);
// 同一日期,同一 FormatStyle.MEDIUM,locale 决定具体模式与月名文本
for (Locale locale : new Locale[] {Locale.US, Locale.CHINA, Locale.GERMANY}) {
DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
.withLocale(locale);
System.out.println(locale + " -> " + billed.format(fmt));
}
// SHORT 紧凑、FULL/LONG 最完整,但 FULL/LONG 要求 temporal 带时区
ZonedDateTime zoned = billed.atStartOfDay(java.time.ZoneId.of("Asia/Shanghai"));
System.out.println("FULL: "
+ zoned.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL)
.withLocale(Locale.US)));
}
}How it works
Structurally, expect the class InvoiceDate and the function main and nothing else.
The cycling part of this snippet is for (Locale locale : new Locale[] {Locale.US, Locale.CHINA, Locale.GERMANY}).
Points of care
- The only prerequisite is the language toolchain itself.
Applying it
Entry signature: public static void main(String[] args)
The run prints FULL: — each prefix names the step that produced it.
Statements that matter
ZonedDateTime zoned = billed.atStartOfDay(java.time.ZoneId.of("Asia/Shanghai"));
DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
.withLocale(locale);
LocalDate billed = LocalDate.of(2026, 11, 23);
Interactive Tools for This Topic
Duration HumanizerTurn a number of seconds into a readable duration such as 1 day, 2 hours, 3 minutes, and show the equivalent in minutes and hours.Indentation ConverterConvert leading indentation between tabs and spaces at a chosen width, leaving inner content untouched.JSON Formatter & ValidatorFormat, beautify, and validate JSON data with configurable indentation. Instantly catches syntax errors and displays a pretty-printed tree structure.JSON SorterSort JSON object keys by code point ascending or descending, recursively or top-level only, preserving array order.
FAQ
- What does Localized Formats Render Per Locale print when run?
- Invoke the file as-is — the `FULL:` prefixes identify which step printed each line.
Report a problem with this exampleOpens a pre-filled issue on GitHub.