Change Week Days Format

Ads
 

Change Week Days Format

This Example shows you how to change week days format. In the code given below we are change week days format.

This Example shows you how to change week days format. In the code given below we are change week days format.

Change Week Days Format

     

This Example shows you how to change week days format. In the code given below we are change week days format.

Methods used in this example are described below :

DateFormatSymbols() : DateFormatSymbols class object used for formatting localizable date-time. It format the months name and days name.

DateFormatSymbols.getShortWeekdays() : getShortWeekdays method returns a string type array and this array have shorted weekdays, For example: "Sun", "Mon", "Tue" etc.

DateFormatSymbols.setShortWeekdays() : setShortWeekdays method is used to set weekday in short format, For example: "Sun", "Mon", etc.

ChangeWeekDays.java



import java.text.*;
import java.util.*;

public class ChangeWeekDays {

  public static void main(String args[]) {
  Date today;
  String result;
  SimpleDateFormat formatter;
  DateFormatSymbols symbols;
  String[] defaultDays;
  String[] modifiedDays;

 symbols = new DateFormatSymbols(new Locale("en""US"));
 defaultDays = symbols.getShortWeekdays();

 for (int i = 0; i < defaultDays.length; i++) {
  System.out.print(defaultDays[i"  ");
 }
 System.out.println();

 String[] capitalDays = 
   {
"""SUN""MON""TUE""WED""THU""FRI","SAT"};
 
symbols.setShortWeekdays(capitalDays);

 modifiedDays = symbols.getShortWeekdays();
  for (int i = 0; i < modifiedDays.length; i++) {
  System.out.print(modifiedDays[i"  ");
  }

  System.out.println();
  System.out.println();

  formatter = new SimpleDateFormat("E", symbols);
  today = new Date();
  result = formatter.format(today);
  System.out.println("Today is : "+result);
  }
}

Output : Output :

  Sun  Mon  Tue  Wed  Thu  Fri  Sat  
  SUN  MON  TUE  WED  THU  FRI  SAT  

Today is : TUE

Download code Download code

     

Ads

Ads