Wednesday 4 July 2018

How to use getDisplayNames(int field, int style, Locale locale) method of Java.util.calendar class


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

CalendarDemo.java

import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
/**
 * public Map<String,Integer> getDisplayNames(int field, int
 *                                              style, Locale locale)
 *
 * Parameters:
 *
 * field - the calendar field for which the display names are
 * returned
 *
 * style - the style applied to the string representation; one
 * of SHORT_FORMAT (SHORT), SHORT_STANDALONE, LONG_FORMAT
 * (LONG), LONG_STANDALONE, NARROW_FORMAT, or
 * NARROW_STANDALONE
 *
 * locale - the locale for the display names
 *
 * Returns:
 *
 * a Map containing all display names in style and locale and
 * their field values, or null if no display names are defined
 * for field
 */

public class CalendarDemo
{
    public static void main(String[] args)
    {
        Calendar cal = Calendar.getInstance();
        Locale locale = Locale.getDefault();
        System.out.println(locale);
        Map<String, Integer> map = cal.getDisplayNames(Calendar.DAY_OF_WEEK,
                Calendar.LONG, locale);
        System.out.println(map);

    }

}

Output

en_US
{Monday=2, Thursday=5, Friday=6, Sunday=1, Wednesday=4, Tuesday=3, Saturday=7}

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/259a72fc482a7b514359596bbc1084e51fbbf105/BasicJava_2018/CalendarDemo_getDisplayNames_map/?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