Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Example program to change Date formatting Symbols 
 

In the previous section of examples you have learned about how to create date and how to format them and many such examples. Now you will learn how we can change the formatting symbols for date.

 

Example program to change Date formatting Symbols

                         

In the previous section of examples you have learned about how to create date and how to format them and many such examples. Now you will learn how we can change the formatting symbols for date.

In this example of changing the date formatting symbols we have used DateFormatSymbols class. In this class we have used four different methods of DateFormatSymbols class.

DateFormatSymbols symbols = new DateFormatSymbols();
        symbols.setMonths(MONTHS);

above lines of code sets symbols for Months with the string array MONTHS. It sets months full name symbol.

 symbols.setShortMonths(ShortMONTHS);
 
sets months short name symbols.

 symbols.setWeekdays(Weekdays);
 
sets Weekdays full name symbol.

symbols.setShortWeekdays(shortWeekdays);
 
sets Weekdays symbols name in short.

Here is the full example code of DateSymbolsFormat.java as follows:

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.DateFormatSymbols;
 
public class DateSymbolsFormat {
    public static void main(String[] args) {
        String[] MONTHS = {"JANUARY""FEBRUARY""MARCH""APRIL""MAY""JUNE",
                "JULY""AUGUST""SEPTEMBER""OCTOBER""NOVEMBER""DECEMBER"};
        String[] ShortMONTHS = {"JAN""FEB""MAR""APR""MAY""JUN",
                "JUL""AUG""SEP""OCT""NOV""DEC"};
        String[] Weekdays = {"""MONDAY""TUESDAY""WEDNESDAY",
                
"THURSDAY""FRIDAY""SATURDAY""SUNDAY"};
        String[] shortWeekdays = {"""MON""TUE""WED""THU""FRI""SAT""SUN"};
 
        DateFormatSymbols symbols = new DateFormatSymbols();
      symbols.setMonths(MONTHS);
      symbols.setShortMonths(ShortMONTHS);
      symbols.setWeekdays(Weekdays);
      symbols.setShortWeekdays(shortWeekdays);

      ////////////////////////////////////////////////////////////////
     // Format date into dd-MMMM-yyyy format e.g 10-OCTOBER-2008   //
    ////////////////////////////////////////////////////////////////
      DateFormat format = new SimpleDateFormat("dd-MMMM-yyyy", symbols);
      System.out.println(format.format(new Date()));
        
     /////////////////////////////////////////////////////////////
    // Format date into dd-MMM-yyyy format e.g 10-OCT-2008     //
   /////////////////////////////////////////////////////////////
      format = new SimpleDateFormat("dd-MMM-yyyy", symbols);
      System.out.println(format.format(new Date()));
 
     ///////////////////////////////////////////////////////////////////////////
    //  Format date into EEEE, dd-MMM-yyyy format e.g SATURDAY,10-OCT-2008   //
   ///////////////////////////////////////////////////////////////////////////
      format = new SimpleDateFormat("EEEE, dd-MMM-yyyy", symbols);
      System.out.println(format.format(new Date()));

     ///////////////////////////////////////////////////////////////////////////
    //  Format date into E, dd-MMM-yyyy format e.g SAT,10-OCT-2008           //
   ///////////////////////////////////////////////////////////////////////////
        format = new SimpleDateFormat("E, dd-MMM-yyyy", symbols);
        System.out.println(format.format(new Date()));
    }
}

To run this example create and save  DateSymbolsFormat.java . Compile this class with the javac command and execute it with the java command. You will get the following output on your command prompt.

Output: 

C:\DateExample>javac DateSymbolsFormat.java

C:\DateExample>java DateSymbolsFormat
10-OCTOBER-2008
10-OCT-2008
SATURDAY, 10-OCT-2008
SAT, 10-OCT-2008

Download Source Code

                         

» View all related tutorials
Related Tags: java c class time calendar method arguments field this ai package ie example add with mount program ram exam span

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.