Day Names Per Locale With TextStyle

Render weekday and month names per locale with ofPattern().withLocale() and getDisplayName, where TextStyle chooses full, short, or narrow.

JavaConfig Management

Code

snippet
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.util.Locale;

public class DayNames {

    public static void main(String[] args) {
        // 2026-11-15 是星期日;同一个日期,三种语言各自的月份与星期名
        LocalDate sunday = LocalDate.of(2026, 11, 15);
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("EEEE d MMMM uuuu");

        for (Locale locale : new Locale[] {Locale.US, Locale.GERMANY, Locale.CHINA}) {
            System.out.println(locale + " -> " + sunday.format(pattern.withLocale(locale)));
        }

        // 只要星期几的名字:TextStyle 控制全称/缩写/单字母
        DayOfWeek dow = sunday.getDayOfWeek();
        System.out.println("full  : " + dow.getDisplayName(TextStyle.FULL, Locale.US));
        System.out.println("short : " + dow.getDisplayName(TextStyle.SHORT, Locale.US));
        System.out.println("narrow: " + dow.getDisplayName(TextStyle.NARROW, Locale.US));
    }
}

One date, three locales

The fixed date LocalDate.of(2026, 11, 15) — a Sunday — is formatted with ofPattern(“EEEE d MMMM uuuu”) and withLocale for Locale.US, Locale.GERMANY, and Locale.CHINA, so the same instant yields three different weekday and month names.

TextStyle for single names

When only the weekday name is needed, getDayOfWeek().getDisplayName(…) renders it in TextStyle.FULL (Sunday), TextStyle.SHORT (Sun), and TextStyle.NARROW (S) against Locale.US.

Where this applies

UI labels and reports that must localize dates should go through these locale-aware formatters rather than hand-built arrays, which drift per language.

Interactive Tools for This Topic

FAQ

How do you format the same date for several locales?
Create the formatter once with ofPattern and call withLocale(locale) per target, as the demo does for US, GERMANY, and CHINA.
When is TextStyle.NARROW appropriate?
For very tight layouts; narrow forms may be ambiguous (S for both Sunday and Saturday), so they are not for distinguishing values.