Calendar類的getDisplayName(int cal_field,int cal_style,Locale local)方法用於以給定樣式(int cal_style)和locale(int local)返回日曆字段(int cal_field)值的字符串表示形式。
用法:
public String getDisplayName(int cal_field, int cal_style, Locale local)
參數:該方法具有三個參數:
- cal_field:這是整數類型,是指要在其上執行操作的日曆字段。
- cal_style:這是整數類型,是指應該應用於字符串表示形式的樣式。
- local:這是Locale對象類型,是指表示字符串的語言環境。
返回值:該方法以傳遞樣式的形式返回給定字段的字符串表示形式,如果沒有可用的字符串表示形式,則返回null。
以下示例程序旨在說明Calendar類的getDisplayName()方法的用法:
示例1:
// Java Code to illustrate
// getDisplayName() Method
import java.util.*;
public class Calendar_Demo_Locale {
public static void main(String args[])
{
// Creating Locale objects class
Locale first_obj = new Locale("TURKISH", "Turkey");
Locale sec_obj = new Locale("ENGLISH", "UK");
// Displaying the objects
System.out.println("First"
+ " object is : " + first_obj);
System.out.println("Second"
+ " object is : " + sec_obj);
// Getting the display names
String obj_nm = first_obj.getDisplayName();
// Displaying the results
System.out.println("Name of the"
+ " first object: " + obj_nm);
// Getting the display names
obj_nm = sec_obj.getDisplayName();
System.out.println("Name of the"
+ " second object: " + obj_nm);
}
}
輸出:
First object is : turkish_TURKEY Second object is : english_UK Name of the first object: turkish (TURKEY) Name of the second object: english (UK)
示例2:
// Java Code to illustrate
// getDisplayName() Method
import java.util.*;
public class Calendar_Demo_Locale {
public static void main(String args[])
{
// Creating Locale objects class
Locale first_obj = new Locale("RUSSIAN", "Russia");
Locale sec_obj = new Locale("GERMAN", "Germany");
// Displaying the objects
System.out.println("First"
+ " object is : " + first_obj);
System.out.println("Second"
+ " object is : " + sec_obj);
// Getting the display names
String obj_nm = first_obj.getDisplayName();
// Displaying the results
System.out.println("Name of the"
+ " first object: " + obj_nm);
// Getting the display names
obj_nm = sec_obj.getDisplayName();
System.out.println("Name of the"
+ " second object: " + obj_nm);
}
}
輸出:
First object is : russian_RUSSIA Second object is : german_GERMANY Name of the first object: russian (RUSSIA) Name of the second object: german (GERMANY)
相關用法
- Java TimeZone getDisplayName()用法及代碼示例
- Java Locale getDisplayName()用法及代碼示例
- Java ZoneOffset getDisplayName()用法及代碼示例
- Java ZoneId getDisplayName()用法及代碼示例
- Java DayOfWeek getDisplayName()用法及代碼示例
- Java TimeZone getDisplayName(boolean, int)用法及代碼示例
- Java TimeZone getDisplayName(Locale locale)用法及代碼示例
- Java Calendar add()用法及代碼示例
- Java Calendar set()用法及代碼示例
- Java Calendar get()用法及代碼示例
- Java Locale getDisplayName(Locale)用法及代碼示例
- Java Calendar isLenient()用法及代碼示例
- Java Calendar getActualMinimum()用法及代碼示例
- Java Calendar hashCode()用法及代碼示例
- Java Calendar getTime()用法及代碼示例
注:本文由純淨天空篩選整理自Chinmoy Lenka大神的英文原創作品 Calendar getDisplayName() Method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。