Wednesday, July 3, 2024
HomeLanguagesJavaSimpleDateFormat getDateFormatSymbols() Method in Java with Examples

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:




// 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] + " ");
        }
    }
}


Output:

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

Example 2:




// 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] + " ");
        }
    }
}


Output:

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

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments