Write a Java program to get localized day in week name


The code you provided is a Java program that uses the java.util, java.time, and java.text packages to get the names of the days of the week in a specific locale and print them to the console. Here is a breakdown of the code:

  • The java.util, java.time, and java.text packages are imported at the beginning of the code.
  • The Localized_WeekName class is defined, which contains the main method.
  • Within the main method, a new DateFormatSymbols object is created with a Locale parameter of "de", which represents the German language and culture.
  • The getWeekdays() method is called on the symbols variable, which returns an array of strings containing the names of the days of the week in the specified locale. This array is stored in the day_name variable.
  • A for-each loop is used to iterate through the day_name array and print each element to the console using the System.out.println() method.

Source Code

import java.util.*;
import java.time.*;
import java.text.*;
 
public class Localized_WeekName
{
	public static void main(String []args)
	{
		DateFormatSymbols symbols = new DateFormatSymbols(new Locale("de"));
		String[] day_name = symbols.getWeekdays();
		for (String n : day_name)
		{ 
			System.out.println(n);
		}
	}
}

Output

Sonntag
Montag
Dienstag
Mittwoch
Donnerstag
Freitag
Samstag

Example Programs