Wednesday, October 15, 2025
HomeLanguagesJavaDateFormatSymbols getShortMonths() Method in Java with Examples

DateFormatSymbols getShortMonths() Method in Java with Examples

The getShortMonths() Method of DateFormatSymbols class in Java is used to get the short name of the months of the calendar in a string format.

Syntax:

public String[] getMonths()

Parameters: The method does not take any parameters.

Return Values: The method returns the short name of the months in a string format.

Below programs illustrate the use of getShortMonths() method.
Example 1:




// Java code to demonstrate getShortMonths()
  
import java.text.DateFormatSymbols;
  
public class DateFormat_Main {
    public static void main(String args[])
    {
  
        int i;
  
        // Initializing DateFormatSymbols
        String months[]
            = new DateFormatSymbols()
                  .getShortMonths();
  
        for (i = 0; i < months.length - 1; i++) {
  
            // Displaying the short months
            System.out.println(
                "Month = " + months[i]);
        }
    }
}


Output:

Month = Jan
Month = Feb
Month = Mar
Month = Apr
Month = May
Month = Jun
Month = Jul
Month = Aug
Month = Sep
Month = Oct
Month = Nov
Month = Dec

Example 2:




// Java code to demonstrate getShortMonths()
  
import java.text.DateFormatSymbols;
  
public class DateFormat_Main {
    public static void main(String args[])
    {
  
        int i;
  
        // Initializing DateFormatSymbols
        String months[]
            = new DateFormatSymbols()
                  .getShortMonths();
  
        for (i = 0; i < months.length / 2; i++) {
  
            // Displaying the short months
            System.out.println(
                "Month " + i + " = " + months[i]);
        }
    }
}


Output:

Month 0 = Jan
Month 1 = Feb
Month 2 = Mar
Month 3 = Apr
Month 4 = May
Month 5 = Jun

Reference: https://docs.oracle.com/javase/8/docs/api/java/text/DateFormatSymbols.html#getShortMonths–

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11891 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11952 POSTS0 COMMENTS
Shaida Kate Naidoo
6851 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS