Friday, 8 June 2018

How to use getDisplayName(TextStyle style, Locale locale) method of DayOfWeek Enum


Click here to watch on Youtube:
https://www.youtube.com/watch?v=XgCCaJriQmk&list=UUhwKlOVR041tngjerWxVccw 

DayOfWeekDemo.java

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

public class DayOfWeekDemo
{
    public static void main(String[] args)
    {
        DayOfWeek dayOfWeek = DayOfWeek.TUESDAY;

        /*
         * Gets the textual representation, such as 'Mon' or 'Friday'.
         *
         * Parameters:
         *
         * style - the length of the text required, not null
         *
         * locale - the locale to use, not null
         *
         * Returns:
         *
         * the text value of the day-of-week, not null
         */

        System.out.println("Full   = "+dayOfWeek.getDisplayName(TextStyle.FULL, Locale.US));
        System.out
                .println("Short  = "+dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.US));
        System.out
                .println("Narrow =  "+dayOfWeek.getDisplayName(TextStyle.NARROW, Locale.US));
    }

}

Output

Full   = Tuesday
Short  = Tue
Narrow =  T

Click the below link to download the code:
https://sites.google.com/site/ramj2eev2/java_basics/DayOfWeekDemo_getDisplayName.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava_2018/DayOfWeekDemo_getDisplayName

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/23d89f367bac9ed4230eafe0abaf49c0a80cc445/BasicJava_2018/DayOfWeekDemo_getDisplayName/?at=master

See also:
  • All JavaEE Videos Playlist
  • All JavaEE Videos
  • All JAVA EE Links
  • Spring Tutorial
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • Cooking Tutorial
  • No comments:

    Post a Comment