Java Program to get display name for Day of Week in different locale


To get the display name for Day of Week in different locale, let us first get the default −

Locale locale = Locale.getDefault();

Now, let’s say we want to consider Canada locale −

Locale locale1 = Locale.CANADA;

Now, get the Day of Week name for locale default and Canada −

System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale));
System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale1));

Example

 Live Demo

import java.time.DayOfWeek;
import java.time.format.TextStyle;
import java.util.Locale;
public class Demo {
   public static void main(String[] args) {
      Locale locale = Locale.getDefault();
      Locale locale1 = Locale.CANADA;
      System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale));
      System.out.printf("%s%n", DayOfWeek.THURSDAY.minus(2).getDisplayName(TextStyle.SHORT, locale1));
      Locale locale2 = Locale.FRENCH;
      System.out.printf("%s%n", DayOfWeek.SUNDAY.minus(10).getDisplayName(TextStyle.SHORT, locale2));
   }
}

Output

Tue
Tue.
jeu.

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

214 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements