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

Java 8Object Oriented ProgrammingProgramming

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.
raja
Published on 25-Apr-2019 09:47:57
Advertisements