java.time.DayOfWeek.getDisplayName() Method Example



Description

The java.time.DayOfWeek.getDisplayName(TextStyle style, Locale locale) method gets the textual representation, such as 'Mon' or 'Friday'.

Declaration

Following is the declaration for java.time.DayOfWeek.getDisplayName(TextStyle style, Locale locale) method.

public String getDisplayName(TextStyle style, Locale locale)

Parameters

  • style − the length of the text required, not null.

  • locale − the locale to use, not null.

Return Value

the text value of the day-of-week, not null.

Example

The following example shows the usage of java.time.DayOfWeek.getDisplayName(TextStyle style, Locale locale) method.

package com.tutorialspoint;

import java.time.DayOfWeek;
import java.time.format.TextStyle;
import java.util.Locale;

public class DayOfWeekDemo {
   public static void main(String[] args) {
 
      DayOfWeek day = DayOfWeek.of(3);
      System.out.println(day.getDisplayName(TextStyle.SHORT,Locale.ENGLISH));  
   }
}

Let us compile and run the above program, this will produce the following result −

Wed
Advertisements