Saturday, September 6, 2025
HomeLanguagesJavaDayOfWeek getDisplayName() method in Java with Examples

DayOfWeek getDisplayName() method in Java with Examples

The getDisplayName() method of java.time.DayOfWeek is an in-built function in Java which returns the textual representation of the day-of-week according to the specified Locale class parameter and TextStyle. The TextStyle defines three elements ‘FULL’, ‘SHORT’ and ‘NARROW’. Locale class represents a specific language and region of the world.

Method Declaration:

 public String getDisplayName(TextStyle style, Locale locale)

Syntax:

 String text = dayOfWeekObject.getDisplayName(TextStyle style, Locale locale)

Parameters: This method takes two parameters:

  • style – is the TestStyle which can be three elements ‘FULL’, ‘SHORT’ and ‘NARROW’.
  • locale – represents a specific language and region of the world. The default locale is US
  • dayOfWeekObject – is an instance of DayOfWeek.
  • Return Value: The function returns returns the textual representation of the day-of-week according to the specified Locale class parameter and TextStyle.

    Below programs illustrate the above method:
    Program 1:




    // Java Program Demonstrate getDisplayName()
    // method of DayOfWeek
      
    import java.time.*;
    import java.time.format.TextStyle;
    import java.util.Locale;
      
    class DayOfWeekExample {
        public static void main(String[] args)
        {
            // Initializing a DayOfWeek instance
            DayOfWeek dayOfWeek = DayOfWeek.MONDAY;
      
            // Get textual representation of the
            // day-of-week in FULL style
            String full_name
                = dayOfWeek
                      .getDisplayName(TextStyle.FULL,
                                      Locale.getDefault());
      
            // Get textual representation of the
            // day-of-week in SHORT style
            String short_name
                = dayOfWeek
                      .getDisplayName(TextStyle.SHORT,
                                      Locale.getDefault());
      
            // Get textual representation of the
            // day-of-week in NARROW style
            String narrow_name
                = dayOfWeek
                      .getDisplayName(TextStyle.NARROW,
                                      Locale.getDefault());
      
            // Printing the textual names of the day-of-week
            System.out.println(full_name);
      
            System.out.println(short_name);
      
            System.out.println(narrow_name);
        }
    }

    
    
    Output:

    Monday
    Mon
    M
    

    Program 2:




    // Java Program Demonstrate getDisplayName()
    // method of DayOfWeek
      
    import java.time.*;
    import java.time.DayOfWeek;
    import java.time.format.TextStyle;
    import java.util.Locale;
      
    class DayOfWeekExample {
        public static void main(String[] args)
        {
            // Initializing a DayOfWeek instance
            DayOfWeek dayOfWeek = DayOfWeek.WEDNESDAY;
      
            // Get textual representation of the
            // day-of-week in FULL style
            String full_name
                = dayOfWeek
                      .getDisplayName(TextStyle.FULL,
                                      Locale.getDefault());
      
            // Get textual representation of the
            // day-of-week in SHORT style
            String short_name
                = dayOfWeek
                      .getDisplayName(TextStyle.SHORT,
                                      Locale.getDefault());
      
            // Get textual representation of the
            // day-of-week in NARROW style
            String narrow_name
                = dayOfWeek
                      .getDisplayName(TextStyle.NARROW,
                                      Locale.getDefault());
      
            // Printing the textual names of the day-of-week
            System.out.println(full_name);
      
            System.out.println(short_name);
      
            System.out.println(narrow_name);
        }
    }

    
    
    Output:

    Wednesday
    Wed
    W
    

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

    RELATED ARTICLES

    Most Popular

    Dominic
    32270 POSTS0 COMMENTS
    Milvus
    82 POSTS0 COMMENTS
    Nango Kala
    6639 POSTS0 COMMENTS
    Nicole Veronica
    11803 POSTS0 COMMENTS
    Nokonwaba Nkukhwana
    11869 POSTS0 COMMENTS
    Shaida Kate Naidoo
    6752 POSTS0 COMMENTS
    Ted Musemwa
    7029 POSTS0 COMMENTS
    Thapelo Manthata
    6705 POSTS0 COMMENTS
    Umr Jansen
    6721 POSTS0 COMMENTS