java calendar
日歷類的getDisplayNames()方法 (Calendar Class getDisplayNames() method)
getDisplayNames() method is available in java.util package.
getDisplayNames()方法在java.util包中可用。
getDisplayNames() method is used to return Map that contains all field names of the calendar will be updated in the given field(fi) values in the given style(st) and Locale(lo).
getDisplayNames()方法用于返回包含日歷所有字段名稱的Map,這些日歷名稱將在給定style(st)和Locale(lo)的給定field(fi)值中更新。
getDisplayNames() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
getDisplayNames()方法是一個非靜態方法,可通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。
getDisplayNames() method may throw an exception at the time of returning Map object.
getDisplayNames()方法在返回Map對象時可能會引發異常。
- IllegalArgumentException: This exception may throw when the given field(fi) or style(st) are not valid.IllegalArgumentException :如果給定的field(fi)或style(st)無效,則可能引發此異常。
- NullPointerException: This exception may throw when the given parameter Locale(lo) is null exists.NullPointerException :如果給定參數Locale(lo)為null,則可能引發此異常。
Syntax:
句法:
public Map getDisplayNames(int fi, int st, Locale lo);
Parameter(s):
參數:
int fi – it represents the field(fi) of this Calendar.
int fi –它代表此日歷的字段(fi)。
int st – it represents the style that will implemented to the string denotation.
int st –它表示將對字符串符號實施的樣式。
Locale lo – it represents the locale of the string denotation.
語言環境lo –它表示字符串符號的語言環境。
Return value:
返回值:
The return type of the method is String, it returns Map object that contains names display in the given style and locale and their desired field(fi) values otherwise it returns null when no string denotation exists.
該方法的返回類型為String ,它返回Map對象,該對象包含以給定樣式和語言環境顯示的名稱以及所需的field(fi)值,否則,當不存在任何字符串符號時,它返回null。
Example:
例:
// Java Program to demonstrate the example of
// Map getDisplayNames() method of Calendar
import java.util.*;
public class GetDisplayNames {
public static void main(String args[]) {
// Instantiating a Calendar object
Calendar ca = Calendar.getInstance();
// Instantiating a Locale object
Locale lo = Locale.getDefault();
// By using getDisplayNames() method is to
// display the names
Map < String, Integer > m = ca.getDisplayNames(Calendar.DAY_OF_WEEK,
Calendar.LONG, lo);
NavigableMap < String, Integer > nm = new TreeMap < String, Integer > (m);
// Displaying the results
System.out.println(" ca.getDisplayNames(): " + nm);
}
}
Output
輸出量
ca.getDisplayNames(): {Friday=6, Monday=2, Saturday=7, Sunday=1, Thursday=5, Tuesday=3, Wednesday=4}
翻譯自: https://www.includehelp.com/java/calendar-getdisplaynames-method-with-example.aspx
java calendar