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
import java.text.DateFormatSymbols;
import java.util.Locale;
public class DateFormat_Main {
public static void main(String args[])
{
DateFormatSymbols format
= new DateFormatSymbols(
new Locale( "en" , "US" ));
String[] shDays
= format.getShortWeekdays();
System.out.print( "Original: " );
for ( int i = 1 ; i < shDays.length; i++) {
System.out.print(shDays[i] + " " );
}
System.out.println();
String[] modDays = { "WED" , "THU" , "FRI" ,
"MON" , "TUE" , "SUN" , "SAT" };
format.setShortWeekdays(modDays);
String[] modifiedDays
= format.getShortWeekdays();
System.out.print( "Modified: " );
for ( int i = 0 ; i < modifiedDays.length; i++) {
System.out.print(modifiedDays[i] + " " );
}
}
}
|
Output:
Original: Sun Mon Tue Wed Thu Fri Sat
Modified: WED THU FRI MON TUE SUN SAT
Example 2:
Java
import java.text.DateFormatSymbols;
import java.util.Locale;
public class DateFormat_Main {
public static void main(String args[])
{
DateFormatSymbols format
= new DateFormatSymbols(
new Locale( "en" , "US" ));
String[] shDays = format.getShortWeekdays();
System.out.print( "Original: " );
for ( int i = 1 ; i < shDays.length; i++) {
System.out.print(shDays[i] + " " );
}
System.out.println();
String[] modDays = { "WED" , "THU" , "FRI" ,
"MON" , "TUE" , "SUN" ,
"SAT" , "ONE" , "TWO" };
format.setShortWeekdays(modDays);
String[] modifiedDays
= format.getShortWeekdays();
System.out.print( "Modified: " );
for ( int i = 0 ; i < modifiedDays.length; i++) {
System.out.print(modifiedDays[i] + " " );
}
}
}
|
Output:
Original: Sun Mon Tue Wed Thu Fri Sat
Modified: WED THU FRI MON TUE SUN SAT ONE TWO
Reference: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#setShortWeekdays-java.lang.String:A-
Last Updated :
24 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...