java.util.Calendar.getDisplayNames()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中java.util.Calendar.getDisplayNames()方法的一些代码示例,展示了Calendar.getDisplayNames()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Calendar.getDisplayNames()方法的具体详情如下:
包路径:java.util.Calendar
类名称:Calendar
方法名:getDisplayNames

Calendar.getDisplayNames介绍

[英]Returns a map of human-readable strings to corresponding values, for the given field, style, and locale. Returns null if no strings are available.

For example, getDisplayNames(MONTH, ALL_STYLES, Locale.US) would contain mappings from "Jan" and "January" to #JANUARY, and so on.
[中]

代码示例

代码示例来源:origin: ltsopensource/light-task-scheduler

private static Map<String, Integer> getDisplayNames(final int field, final Calendar definingCalendar, final Locale locale) {
  return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}

代码示例来源:origin: ltsopensource/light-task-scheduler

private static Map<String, Integer> getDisplayNames(final int field, final Calendar definingCalendar, final Locale locale) {
  return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * 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
 * @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;
}

代码示例来源:origin: looly/hutool

/**
 * 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
 * @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;
}

代码示例来源:origin: looly/hutool

/**
 * 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
 * @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;
}

代码示例来源:origin: io.prestosql.hadoop/hadoop-apache

/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @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);
}

代码示例来源:origin: com.aoindustries/ao-lang

@Override
public Map<String, Integer> getDisplayNames(int field, int style, Locale locale) {
  return wrapped.getDisplayNames(field, style, locale);
}

代码示例来源:origin: com.github.ltsopensource/lts-core

private static Map<String, Integer> getDisplayNames(final int field, final Calendar definingCalendar, final Locale locale) {
  return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
}

代码示例来源:origin: stackoverflow.com

Calendar.getDisplayNames(MONTH, ALL_STYLES, Locale.DUTCH); // returns a map which you can use to match strings

代码示例来源:origin: stackoverflow.com

Set<String> dayNames = Calendar.getInstance()
.getDisplayNames(Calendar.DAY_OF_WEEK,
  Calendar.SHORT,
  Locale.getDefault())
.keySet();

代码示例来源:origin: stackoverflow.com

Calendar cal = Calendar.getInstance();
Map<String, Integer> map = cal.getDisplayNames(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH);
System.out.println(map);

代码示例来源:origin: Nike-Inc/riposte

public AccessLogger() {
  // Setup everything we can in advance now to make date/time formatting as efficient as possible later.
  timezoneString = " " + ZonedDateTime.now().format(DateTimeFormatter.ofPattern("Z"));
  Locale defaultLocale = Locale.getDefault(Locale.Category.FORMAT);
  Map<String, Integer> monthMap =
    Calendar.getInstance().getDisplayNames(Calendar.MONTH, Calendar.SHORT_FORMAT, defaultLocale);
  int maxMonthIndex = Collections.max(monthMap.values());
  shortMonthNames = new String[maxMonthIndex + 1];
  monthMap.entrySet().forEach(entry -> shortMonthNames[entry.getValue()] = entry.getKey());
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
  Locale locale = new Locale("ja", "JP", "JP");
  Calendar now = Calendar.getInstance(locale);
  Map<String, Integer> ears = now.getDisplayNames(Calendar.ERA, Calendar.LONG, new Locale("en"));
  for (Map.Entry<String, Integer> era : ears.entrySet()) {
    Integer eraIndex = era.getValue();
    String eraName = era.getKey();
    System.out.printf("Era #%d [%s]%n", eraIndex, eraName);
    now.set(Calendar.ERA, eraIndex);
    now.set(Calendar.YEAR, 1);
    now.set(Calendar.DAY_OF_YEAR, 1);
    System.out.printf("Actual max year in era is %d%n", now.getActualMaximum(Calendar.YEAR));
  }
}

代码示例来源:origin: stackoverflow.com

String[] monthString = new String[12];
   if (monthString[0] == null) {
     // Get month string by android locale
     // The String will like Jule or May ...
     Map<String, Integer> months = Calendar.getInstance().getDisplayNames(Calendar.MONTH, Calendar.LONG, getResources().getConfiguration().locale);
     for (int i = 0; i < 12; i++) {
       for (String month : months.keySet()) {
         if (i == months.get(month).intValue()) {
           monthString[i] = month;
           months.remove(month);
           break;
         }
       }
     }
   }
  Calendar calendar=Calendar.getInstance();
  calendar.setTime(result);
  StringBuilder sb=new StringBuilder();
  sb.append(monthString[calendar.get(Calendar.MONTH)]);
  //spec your format string...

代码示例来源:origin: com.aliyun.openservices/ons-client

/**
 * 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
 * @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;
}

代码示例来源:origin: de.knightsoft-net/gwt-commons-lang3

/**
 * 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
 * @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;
}

代码示例来源:origin: io.virtdata/virtdata-lib-curves4

/**
 * 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
 * @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;
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 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
 * @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;
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

/**
 * 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
 * @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;
}

代码示例来源:origin: EvoSuite/evosuite

public Map<String, Integer> getDisplayNames(int field, int style, Locale locale) {
  Capturer.capture(Instrumenter.CAPTURE_ID_JAVA_UTIL_CALENDAR, this, "getDisplayNames", "(IILjava/util/Locale;)Ljava/util/Map;", new Object[] {field, style, locale});
  Map<String, Integer> ret = wrappedCalendar.getDisplayNames(field, style, locale);
  Capturer.enable(Instrumenter.CAPTURE_ID_JAVA_UTIL_CALENDAR, this, ret);
  return ret;
}

相关文章