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

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

本文整理了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

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

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

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

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. * @param cal The calendar to obtain the short and long values
  4. * @param locale The locale of display names
  5. * @param field The field of interest
  6. * @param regex The regular expression to build
  7. * @return The map of string display names to field values
  8. */
  9. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  10. final Map<String, Integer> values = new HashMap<>();
  11. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  12. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  13. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  14. final String key = displayName.getKey().toLowerCase(locale);
  15. if (sorted.add(key)) {
  16. values.put(key, displayName.getValue());
  17. }
  18. }
  19. for (final String symbol : sorted) {
  20. simpleQuote(regex, symbol).append('|');
  21. }
  22. return values;
  23. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. *
  4. * @param cal The calendar to obtain the short and long values
  5. * @param locale The locale of display names
  6. * @param field The field of interest
  7. * @param regex The regular expression to build
  8. * @return The map of string display names to field values
  9. */
  10. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  11. final Map<String, Integer> values = new HashMap<>();
  12. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  13. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  14. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  15. final String key = displayName.getKey().toLowerCase(locale);
  16. if (sorted.add(key)) {
  17. values.put(key, displayName.getValue());
  18. }
  19. }
  20. for (final String symbol : sorted) {
  21. simpleQuote(regex, symbol).append('|');
  22. }
  23. return values;
  24. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. *
  4. * @param cal The calendar to obtain the short and long values
  5. * @param locale The locale of display names
  6. * @param field The field of interest
  7. * @param regex The regular expression to build
  8. * @return The map of string display names to field values
  9. */
  10. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  11. final Map<String, Integer> values = new HashMap<>();
  12. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  13. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  14. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  15. final String key = displayName.getKey().toLowerCase(locale);
  16. if (sorted.add(key)) {
  17. values.put(key, displayName.getValue());
  18. }
  19. }
  20. for (final String symbol : sorted) {
  21. simpleQuote(regex, symbol).append('|');
  22. }
  23. return values;
  24. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. * @param field The field of interest
  4. * @param definingCalendar The calendar to obtain the short and long values
  5. * @param locale The locale of display names
  6. * @return A Map of the field key / value pairs
  7. */
  8. private static Map<String, Integer> getDisplayNames(final int field, final Calendar definingCalendar, final Locale locale) {
  9. return definingCalendar.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  10. }

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

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

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

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

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

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

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

  1. Set<String> dayNames = Calendar.getInstance()
  2. .getDisplayNames(Calendar.DAY_OF_WEEK,
  3. Calendar.SHORT,
  4. Locale.getDefault())
  5. .keySet();

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

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

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

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

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

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

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

  1. String[] monthString = new String[12];
  2. if (monthString[0] == null) {
  3. // Get month string by android locale
  4. // The String will like Jule or May ...
  5. Map<String, Integer> months = Calendar.getInstance().getDisplayNames(Calendar.MONTH, Calendar.LONG, getResources().getConfiguration().locale);
  6. for (int i = 0; i < 12; i++) {
  7. for (String month : months.keySet()) {
  8. if (i == months.get(month).intValue()) {
  9. monthString[i] = month;
  10. months.remove(month);
  11. break;
  12. }
  13. }
  14. }
  15. }
  16. Calendar calendar=Calendar.getInstance();
  17. calendar.setTime(result);
  18. StringBuilder sb=new StringBuilder();
  19. sb.append(monthString[calendar.get(Calendar.MONTH)]);
  20. //spec your format string...

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. * @param cal The calendar to obtain the short and long values
  4. * @param locale The locale of display names
  5. * @param field The field of interest
  6. * @param regex The regular expression to build
  7. * @return The map of string display names to field values
  8. */
  9. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  10. final Map<String, Integer> values = new HashMap<>();
  11. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  12. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  13. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  14. final String key = displayName.getKey().toLowerCase(locale);
  15. if (sorted.add(key)) {
  16. values.put(key, displayName.getValue());
  17. }
  18. }
  19. for (final String symbol : sorted) {
  20. simpleQuote(regex, symbol).append('|');
  21. }
  22. return values;
  23. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. * @param cal The calendar to obtain the short and long values
  4. * @param locale The locale of display names
  5. * @param field The field of interest
  6. * @param regex The regular expression to build
  7. * @return The map of string display names to field values
  8. */
  9. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  10. final Map<String, Integer> values = new HashMap<>();
  11. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  12. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  13. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  14. final String key = displayName.getKey().toLowerCase(locale);
  15. if (sorted.add(key)) {
  16. values.put(key, displayName.getValue());
  17. }
  18. }
  19. for (final String symbol : sorted) {
  20. simpleQuote(regex, symbol).append('|');
  21. }
  22. return values;
  23. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. * @param cal The calendar to obtain the short and long values
  4. * @param locale The locale of display names
  5. * @param field The field of interest
  6. * @param regex The regular expression to build
  7. * @return The map of string display names to field values
  8. */
  9. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  10. final Map<String, Integer> values = new HashMap<>();
  11. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  12. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  13. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  14. final String key = displayName.getKey().toLowerCase(locale);
  15. if (sorted.add(key)) {
  16. values.put(key, displayName.getValue());
  17. }
  18. }
  19. for (final String symbol : sorted) {
  20. simpleQuote(regex, symbol).append('|');
  21. }
  22. return values;
  23. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. *
  4. * @param cal The calendar to obtain the short and long values
  5. * @param locale The locale of display names
  6. * @param field The field of interest
  7. * @param regex The regular expression to build
  8. * @return The map of string display names to field values
  9. */
  10. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  11. final Map<String, Integer> values = new HashMap<>();
  12. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  13. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  14. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  15. final String key = displayName.getKey().toLowerCase(locale);
  16. if (sorted.add(key)) {
  17. values.put(key, displayName.getValue());
  18. }
  19. }
  20. for (final String symbol : sorted) {
  21. simpleQuote(regex, symbol).append('|');
  22. }
  23. return values;
  24. }

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

  1. /**
  2. * Get the short and long values displayed for a field
  3. * @param cal The calendar to obtain the short and long values
  4. * @param locale The locale of display names
  5. * @param field The field of interest
  6. * @param regex The regular expression to build
  7. * @return The map of string display names to field values
  8. */
  9. private static Map<String, Integer> appendDisplayNames(final Calendar cal, final Locale locale, final int field, final StringBuilder regex) {
  10. final Map<String, Integer> values = new HashMap<>();
  11. final Map<String, Integer> displayNames = cal.getDisplayNames(field, Calendar.ALL_STYLES, locale);
  12. final TreeSet<String> sorted = new TreeSet<>(LONGER_FIRST_LOWERCASE);
  13. for (final Map.Entry<String, Integer> displayName : displayNames.entrySet()) {
  14. final String key = displayName.getKey().toLowerCase(locale);
  15. if (sorted.add(key)) {
  16. values.put(key, displayName.getValue());
  17. }
  18. }
  19. for (final String symbol : sorted) {
  20. simpleQuote(regex, symbol).append('|');
  21. }
  22. return values;
  23. }

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

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

相关文章