Java Date Time - DayOfWeek getDisplayName(TextStyle style, Locale locale) example








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

Syntax

getDisplayName has the following syntax.

public String getDisplayName(TextStyle style,   Locale locale)

Example

The following example shows how to use getDisplayName.

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;
/*  w  w w  .  j a va2s  . c om*/
public class Main {
  public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, Month.JUNE, 21);
    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);
    System.out.println(dayOfWeek.getDisplayName(TextStyle.FULL, Locale.CANADA));
    System.out.println(dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.CANADA));
    System.out.println(dayOfWeek.getDisplayName(TextStyle.NARROW, Locale.CANADA));
  }
}

The code above generates the following result.