Close

Java Date Time - DayOfWeek.getDisplayName() Examples

Java Date Time Java Java API 


Class:

java.time.DayOfWeek

java.lang.Objectjava.lang.Objectjava.lang.Enumjava.lang.Enumjava.lang.ComparableComparablejava.io.SerializableSerializablejava.time.DayOfWeekjava.time.DayOfWeekjava.time.temporal.TemporalAccessorTemporalAccessorjava.time.temporal.TemporalAdjusterTemporalAdjusterLogicBig

Method:

public String getDisplayName(TextStyle style,

Locale locale)

The method DayOfWeek.getDisplayName() gets the textual representation according to the specified locale parameter.

The enum TextStyle defines three elements 'FULL', 'SHORT' and 'NARROW'. Each of these three styles have 'standard' and 'stand-alone' variations.

There's no difference between standard and stand-alone display text in a language like English, but some languages treat them differently. For example the display portion of 'day' extracted from a date object can be different than a stand-alone day which is not extracted from a date.


Examples


Using the default locale (US).

package com.logicbig.example.dayofweek;

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

public class GetDisplayNameExample {
public static void main (String[] args) {
DayOfWeek d = DayOfWeek.WEDNESDAY;
System.out.println(d.getDisplayName(TextStyle.FULL,
Locale.getDefault()));
System.out.println(d.getDisplayName(TextStyle.FULL_STANDALONE,
Locale.getDefault()));
System.out.println(d.getDisplayName(TextStyle.SHORT,
Locale.getDefault()));

System.out.println(d.getDisplayName(TextStyle.SHORT_STANDALONE,
Locale.getDefault()));

System.out.println(d.getDisplayName(TextStyle.NARROW,
Locale.getDefault()));

System.out.println(d.getDisplayName(TextStyle.NARROW_STANDALONE,
Locale.getDefault()));
}
}

Output

Wednesday
Wednesday
Wed
Wed
W
3




Using a different locale.

package com.logicbig.example.dayofweek;

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

public class GetDisplayNameExample2 {
public static void main (String[] args) {
DayOfWeek d = DayOfWeek.WEDNESDAY;
System.out.println(d.getDisplayName(TextStyle.FULL,
Locale.ITALY));
System.out.println(d.getDisplayName(TextStyle.FULL_STANDALONE,
Locale.ITALY));
System.out.println(d.getDisplayName(TextStyle.SHORT,
Locale.ITALY));

System.out.println(d.getDisplayName(TextStyle.SHORT_STANDALONE,
Locale.ITALY));

System.out.println(d.getDisplayName(TextStyle.NARROW,
Locale.ITALY));

System.out.println(d.getDisplayName(TextStyle.NARROW_STANDALONE,
Locale.ITALY));
}
}

Output

mercoledì
mercoledì
mer
mer
M
3




See Also