Example usage for java.util Calendar ALL_STYLES

List of usage examples for java.util Calendar ALL_STYLES

Introduction

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

Prototype

int ALL_STYLES

To view the source code for java.util Calendar ALL_STYLES.

Click Source Link

Document

A style specifier for #getDisplayNames(int,int,Locale) getDisplayNames indicating names in all styles, such as "January" and "Jan".

Usage

From source file:Main.java

public static void main(String[] args) {

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

    String n = now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.ALL_STYLES, locale);

    System.out.printf(n);//  ww w.  ja va  2  s .c o m
}

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/*  w  w w  . j a v  a 2 s.c om*/
 * @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/*  w w w .  ja  v a 2  s . co 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;
}