Java SimpleDateFormat setDateFormatSymbols() Example

SimpleDateFormat class setDateFormatSymbols() method example. This example shows you how to use setDateFormatSymbols() method.


Syntax is : public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)
Method sets the date and time format symbols of this date format.

Here is the code.
/**
 * @(#) SetDateFormatSymbolsSimpleDateFormat.java
 * A class representing use of method setDateFormatSymbols() of SimpleDateFormat
class in java.text Package.
 * @Version  14-May-2008
 @author   Rose India Team
 */
import java.util.*;
import java.text.*;

class SetDateFormatSymbolsSimpleDateFormat {

    public static void main(String[] args) {

        // Create new Date object that will be initialized to the current date.
        Date date = new Date();
        System.out.println("Date  by  Date  class          : "+date.toString());
        SimpleDateFormat sdf;

        // Create new SimpleDateFormat object that returns default pattern.
        sdf = new SimpleDateFormat();
        String dateFormat = sdf.format(date);
        System.out.println("Date by SimpleDateFormat class : " + dateFormat);

        // getDateFormatSymbols method call for SimpleDateFormat object.
        DateFormatSymbols dfSymbol = sdf.getDateFormatSymbols();
        String[] days = dfSymbol.getWeekdays();
        System.out.print("Symbols used for the week days :");
        for (int i = 0; i < days.length; i++) {
            System.out.println(days[i]);
        }
        String[] newWeekDys = {"Mahendra""Girish""Komal"};
        DateFormatSymbols dfSymbols = new DateFormatSymbols();
        dfSymbols.setWeekdays(newWeekDys);

        // setDateFormatSymbols method call for SimpleDateFormat object.
        sdf.setDateFormatSymbols(dfSymbols);
        dfSymbol = sdf.getDateFormatSymbols();
        days = dfSymbol.getWeekdays();
        System.out.println("\nNew symbols for the week days :");
        for (int i = 0; i < days.length; i++) {
            System.out.println(days[i]);
        }
    }
}

Output of the program.
Date  by  Date  class          : Sat Jun 14 13:15:55 GMT+05:30 2008
Date by SimpleDateFormat class : 6/14/08 1:15 PM
Symbols used for the week days :
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday

New symbols for the week days :
Mahendra
Girish
Komal

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US