DateFormatSymbols setShortWeekdays() Method in Java with Examples
The setShortWeekdays(String[] newShWeekds) Method of DateFormatSymbols class in Java is used to set the short names of the weekdays of the calendar in string format into some different strings. For eg., “Sun” can be changed to “FRI”, “Mon” can be changed to “WED” etc.
Syntax:
public void setShortWeekdays(String[] newShWeekds)
Parameters: The method takes one parameter newShWeekds which is an array of String type and refers to the new strings that are to be replaced in the existing weekdays.
Return Values: The method returns the modified short name of the weekdays in a string format.
Below programs illustrate the use of setShortWeekdays() method.
Example 1:
// Java code to demonstrate setShortWeekdays() import java.text.DateFormatSymbols; import java.util.Locale; public class DateFormat_Main { public static void main(String args[]) { // Initialising DateFormatSymbols object DateFormatSymbols format = new DateFormatSymbols( new Locale("en", "US")); // Taking the default short weekdays String[] shDays = format.getShortWeekdays(); // Displaying the original System.out.print("Original: "); for (int i = 1; i < shDays.length; i++) { System.out.print(shDays[i] + " "); } System.out.println(); // Taking an alternative names String[] modDays = { "WED", "THU", "FRI", "MON", "TUE", "SUN", "SAT" }; // Setting the default into modified format.setShortWeekdays(modDays); // Displaying the mdified string String[] modifiedDays = format.getShortWeekdays(); System.out.print("Modified: "); for (int i = 0; i < modifiedDays.length; i++) { System.out.print(modifiedDays[i] + " "); } } } |
Original: Sun Mon Tue Wed Thu Fri Sat Modified: WED THU FRI MON TUE SUN SAT
Example 2:
// Java code to demonstrate setShortWeekdays() import java.text.DateFormatSymbols; import java.util.Locale; public class DateFormat_Main { public static void main(String args[]) { // Initialising DateFormatSymbols object DateFormatSymbols format = new DateFormatSymbols( new Locale("en", "US")); // Taking the default short weekdays String[] shDays = format.getShortWeekdays(); // Displaying the original System.out.print("Original: "); for (int i = 1; i < shDays.length; i++) { System.out.print(shDays[i] + " "); } System.out.println(); // Taking an alternative names with // additional random strings String[] modDays = { "WED", "THU", "FRI", "MON", "TUE", "SUN", "SAT", "ONE", "TWO" }; // Setting the default into modified format.setShortWeekdays(modDays); // Displaying the mdified string String[] modifiedDays = format.getShortWeekdays(); System.out.print("Modified: "); for (int i = 0; i < modifiedDays.length; i++) { System.out.print(modifiedDays[i] + " "); } } } |
Original: Sun Mon Tue Wed Thu Fri Sat Modified: WED THU FRI MON TUE SUN SAT ONE TWO
Recommended Posts:
- DateFormatSymbols getShortMonths() Method in Java with Examples
- DateFormatSymbols getShortWeekdays() Method in Java with Examples
- DateFormatSymbols getAvailableLocales() Method in Java with Examples
- DateFormatSymbols getMonths() Method in Java with Examples
- DateFormatSymbols getEras() Method in Java with Examples
- DateFormatSymbols setWeekdays() Method in Java with Examples
- DateFormatSymbols getWeekdays() Method in Java with Examples
- DateFormatSymbols getAmPmStrings() Method in Java with Examples
- DateFormatSymbols setMonths() Method in Java with Examples
- DateFormatSymbols setShortMonths() Method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


