Java SimpleDateFormat getDateFormatSymbols() Example

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


Syntax is : public DateFormatSymbols getDateFormatSymbols()
This method returns a copy of the date and time format symbols of this date format.

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

class GetDateFormatSymbolsSimpleDateFormat {

    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[] months = dfSymbol.getMonths();
        System.out.println("Symbols used for the month :");
        for (int i = 0; i < months.length; i++) {
            System.out.println(months[i]);
        }
    }
}

Output of the program.
Date  by  Date  class          : Sat Jun 14 13:05:39 GMT+05:30 2008
Date by SimpleDateFormat class : 6/14/08 1:05 PM
Symbols used for the month :
January
February
March
April
May
June
July
August
September
October
November
December

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

HOME | COPYRIGHT | CONTACT US