SimpleDateFormat getDateFormatSymbols() Method in Java with Examples

The getDateFormatSymbols() Method of SimpleDateFormat class is used to return the copy of the date and time format symbols.

Syntax:

public DateFormatSymbols getDateFormatSymbols()

Parameters: The method does not take any parameters.

Return Value: The method returns a copy of the format symbols.

Below programs illustrate the working of getDateFormatSymbols() Method of SimpleDateFormat:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// getDateFormatSymbols() method
  
import java.text.*;
import java.util.*;
  
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
    {
  
        // Initializing the SDF
        SimpleDateFormat SDFormat
            = new SimpleDateFormat();
  
        // Getting al DateFormatSymbols
        DateFormatSymbols DFSymbol
            = SDFormat.getDateFormatSymbols();
  
        // Getting the months
        String[] month = DFSymbol.getShortMonths();
        System.out.println("The Months are: ");
        for (int i = 0; i < month.length; i++) {
            System.out.println(month[i] + " ");
        }
    }
}

chevron_right


Output:

The Months are: 
Jan 
Feb 
Mar 
Apr 
May 
Jun 
Jul 
Aug 
Sep 
Oct 
Nov 
Dec  

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// getDateFormatSymbols() method
  
import java.text.*;
import java.util.*;
  
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
    {
  
        // Initializing the SDF
        SimpleDateFormat SDFormat
            = new SimpleDateFormat();
  
        // Getting al DateFormatSymbols
        DateFormatSymbols DFSymbol
            = SDFormat.getDateFormatSymbols();
  
        // Getting the weekdays
        String[] days = DFSymbol.getWeekdays();
        System.out.println("The days of the week are: ");
        for (int i = 0; i < days.length; i++) {
            System.out.println(days[i] + " ");
        }
    }
}

chevron_right


Output:

The days of the week are: 
 
Sunday 
Monday 
Tuesday 
Wednesday 
Thursday 
Friday 
Saturday 

Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.