Home Tutorials I18N Change Week Days Format
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Change Week Days Format

Advertisement
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

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 13, 2008

Related Tutorials

Ask Questions?    Discuss: Change Week Days Format  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com