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.

JavaData Fetching

Code

snippet
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

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.