Example usage for java.util Calendar getDisplayNames

List of usage examples for java.util Calendar getDisplayNames

Introduction

In this page you can find the example usage for java.util Calendar getDisplayNames.

Prototype

public Map<String, Integer> getDisplayNames(int field, int style, Locale locale) 

Source Link

Document

Returns a Map containing all names of the calendar field in the given style and locale and their corresponding field values.

Usage

From source file:DisplayNames.java

public static void main(String args[]) {
    Calendar now = Calendar.getInstance();
    // Locale locale = Locale.getDefault();
    Locale locale = Locale.ITALIAN;
    Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
    System.out.println(names);/*from w ww .j a  v a2  s .c om*/
    String name = now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
    System.out.printf("Today is a %s.%n", name);
}

From source file:Main.java

public static void main(String[] args) {

    Calendar now = Calendar.getInstance();
    Locale locale = Locale.getDefault();

    // call the getdisplaynames method
    Map<String, Integer> representations = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);

    NavigableMap<String, Integer> navMap = new TreeMap<String, Integer>(representations);

    // print the results
    System.out.printf("Whole list:%n%s%n", navMap);
}

From source file:com.rdm.common.util.time.FastDateParser.java

/**
 * Get the short and long values displayed for a field
 * @param field The field of interest//from  w  ww .  j  a  va  2s .  c  o m
 * @param definingCalendar The calendar to obtain the short and long values
 * @param locale The locale of display names
 * @return A Map of the field key / value pairs
 */
private static Map<String, Integer> getDisplayNames(final int field, final Calendar definingCalendar,
        final Locale locale) {
    return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParser.java

/**
 * Get the short and long values displayed for a field
 * @param cal The calendar to obtain the short and long values
 * @param locale The locale of display names
 * @param field The field of interest/*from  w w w .j  a  v  a  2 s.  c  o  m*/
 * @param regex The regular expression to build
 * @return The map of string display names to field values
 */
private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field,
        final StringBuilder regex) {
    final Map<String, Integer> values = new HashMap<>();

    final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
    final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
    for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
        final String key = displayName.getKey().toLowerCase(locale);
        if (sorted.add(key)) {
            values.put(key, displayName.getValue());
        }
    }
    for (final String symbol : sorted) {
        simpleQuote(regex, symbol).append('|');
    }
    return values;
}