DayOfWeek getDisplayName(TextStyle style, Locale locale) example

Description

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 av  a  2  s  .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.





















Home »
  Java Date Time »
    java.time Reference »




Clock
DayOfWeek
Duration
Instant
LocalDate
LocalDateTime
LocalTime
Month
MonthDay
OffsetDateTime
OffsetTime
Period
Year
YearMonth
ZonedDateTime
ZoneId
ZoneOffset