Write a Java program to get Current Locale day in week name


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

  • The java.time and java.text packages are imported at the beginning of the code.
  • The CurrentLocal_WeekName class is defined, which contains the main method.
  • Within the main method, a new DateFormatSymbols object is created without a Locale parameter, which defaults to the system's default locale.
  • 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 default 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.

When you run this program, it will output the names of the days of the week in the default locale of the system. The actual names will depend on the default locale set in your system. For example, if your system is set to the English (United States) locale, the output will be "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", and "Saturday".

Source Code

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

Output

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

Example Programs