Wednesday, May 6, 2026
HomeLanguagesJavaMonth getDisplayName() method in Java

Month getDisplayName() method in Java

The getDisplayName() method is a built-in method of the Month ENUM which is used to get the textual representation of the month-of-year specified by this Month instance.

Syntax:

public String getDisplayName(TextStyle style,
                             Locale locale)

Parameters: This method accepts two parameters as described below:

  • style: This parameter specifies the style or the length of the text to be use, i.e., short, long etc.
  • locale: This parameter specified the locale to be used.

Return Value: This method returns the textual representation of the month specified by this Month instance.

Below programs illustrate the above method:

Program 1:




import java.time.*;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;
  
class monthEnum {
    public static void main(String[] args)
    {
        // Create a month instance
        Month month = Month.of(3);
  
        // Generate textual representation
        System.out.println(month.getDisplayName(TextStyle.SHORT,
                                                Locale.ENGLISH));
    }
}


Output:

Mar

Program 2:




import java.time.*;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;
  
class monthEnum {
    public static void main(String[] args)
    {
        // Create a month instance
        Month month = Month.of(12);
  
        // Generate textual representation
        System.out.println(month.getDisplayName(TextStyle.SHORT,
                                                Locale.ENGLISH));
    }
}


Output:

Dec

Reference: https://docs.oracle.com/javase/8/docs/api/java/time/Month.html#getDisplayName-java.time.format.TextStyle-java.util.Locale-

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6889 POSTS0 COMMENTS
Nicole Veronica
12011 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12105 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6962 POSTS0 COMMENTS