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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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));
    }
}

chevron_right


Output:

Mar

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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));
    }
}

chevron_right


Output:

Dec

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

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.




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.