目录

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

描述 (Description)

java.util.Calendar.getDisplayNames()方法返回一个Map,其中包含给定stylelocale日历字段的所有名称及其对应的field值。

声明 (Declaration)

以下是java.util.Calendar.getDisplayNames()方法的声明

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

参数 (Parameters)

  • field - 日历字段。

  • style - 将应用于字符串表示的样式

  • locale - 字符串表示区域设置

返回值 (Return Value)

该方法返回一个Map,其中包含样式和语言环境中的所有显示名称及其字段值,如果没有可用的字符串表示,则返回null

异常 (Exception)

  • IllegalArgumentException - 如果字段或样式无效,或者此Calendar不宽松且任何字段具有无效值

  • NullPointerException - 如果locale为null

例子 (Example)

以下示例显示了java.util.calendar.getDisplayNames()方法的用法。

package com.iowiki;
import java.util.*;
public class CalendarDemo {
   public static void main(String[] args) {
      // create calendar and locale
      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);
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

Whole list:
{Monday=2, Sunday=1, Thursday=5, Friday=6, Saturday=7, Wednesday=4, Tuesday=3}
↑回到顶部↑
WIKI教程 @2018