SimpleDateFormat setDateFormatSymbols() Method in Java with Examples

The setDateFormatSymbols() Method of SimpleDateFormat class is used to set the date and time format symbols of this date format.

Syntax:

public void setDateFormatSymbols(DateFormatSymbols newFormatSymbols)

Parameters: The method takes one parameter newFormatSymbols which refers to the new format symbols into which this Date format is to be set.

Return Value: The method returns void type.

Below programs illustrate the working of setDateFormatSymbols() Method of SimpleDateFormat:
Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// DateFormatSymbols() method
  
import java.text.*;
import java.util.*;
  
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
        throws InterruptedException, ParseException
    {
        // Initializing SimpleDateFormat
        SimpleDateFormat SDFormat
            = new SimpleDateFormat();
  
        // Setting the DateFormatSymbols
        DateFormatSymbols DFSymbols
            = new DateFormatSymbols(
                new Locale("en",
                           "US"));
  
        // Illustrating the set method
        SDFormat.setDateFormatSymbols(DFSymbols);
  
        // Displaying the formats
        Date date = new Date();
        String str_Date1 = SDFormat.format(date);
        System.out.println("The SimpleDateFormat: "
                           + (str_Date1));
  
        // Working of DFS
        String[] the_days
            = DFSymbols.getShortWeekdays();
        int i, j = 1;
        for (i = 1; i < the_days.length; i++) {
            System.out.print("Day" + j++ + " : "
                             + the_days[i] + "\n");
        }
    }
}

chevron_right


Output:

The SimpleDateFormat: 1/30/19 10:27 AM
Day1 : Sun
Day2 : Mon
Day3 : Tue
Day4 : Wed
Day5 : Thu
Day6 : Fri
Day7 : Sat

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// DateFormatSymbols() method
  
import java.text.*;
import java.util.*;
  
public class SimpleDateFormat_Demo {
    public static void main(String[] args)
        throws InterruptedException, ParseException
    {
        // Initializing SimpleDateFormat
        SimpleDateFormat SDFormat
            = new SimpleDateFormat();
  
        // Setting the DateFormatSymbols
        DateFormatSymbols DFSymbols
            = new DateFormatSymbols(
                new Locale("es",
                           "XL"));
  
        // Illustrating the set method
        SDFormat.setDateFormatSymbols(DFSymbols);
  
        // Displaying the formats
        Date date = new Date();
        String str_Date1 = SDFormat.format(date);
        System.out.println("The SimpleDateFormat: "
                           + (str_Date1));
  
        // Working of DFS
        String[] the_days
            = DFSymbols.getShortWeekdays();
        int i, j = 1;
        for (i = 1; i < the_days.length; i++) {
            System.out.print("Day" + j++ + " : "
                             + the_days[i] + "\n");
        }
    }
}

chevron_right


Output:

The SimpleDateFormat: 1/30/19 10:28 AM
Day1 : dom
Day2 : lun
Day3 : mar
Day4 : mi?
Day5 : jue
Day6 : vie
Day7 : s?b


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.