Tuesday, 5 June 2018

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


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

MonthDemo.java

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

public class MonthDemo
{
    public static void main(String[] args)
    {
        Month month = Month.of(3);

        /*
         * Gets the textual representation, such as 'Jan' or
         * 'December'.
         *
         * Parameters:
         *
         * style - the length of the text required, not null
         *
         * locale - the locale to use, not null
         *
         * Returns:
         *
         * the text value of the month-of-year, not null
         */

        System.out
                .println(month.getDisplayName(TextStyle.FULL, Locale.ENGLISH));
        System.out
                .println(month.getDisplayName(TextStyle.SHORT, Locale.ENGLISH));
        System.out.println(
                month.getDisplayName(TextStyle.NARROW, Locale.ENGLISH));
    }

}

Output

March
Mar
M

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8781cb2c398cca3734b090d3a80e4b0023df3f71/BasicJava_2018/MonthDemo_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