Java中的TimeZone类的getDisplayName(Locale locale_time)方法用于获取该TimeZone的特定名称,该名称易于由用户在用户传递的指定语言环境中理解。该名称适用于演示和显示。
用法:
public final String getDisplayName(Locale locale_time)
参数:该方法采用Locale对象类型的一个参数locale_time,表示要在其中提供显示名称的语言环境。
返回值:该方法以指定的语言环境返回TimeZone的显示名称。
下面的程序演示了TimeZone的getDisplayName()方法的用法:
范例1:
// Java code to illustrate getDisplayName()
import java.util.*;
public class TimeZone_Demo {
public static void main(String args[])
{
// Creating a time zone object
TimeZone timezone
= TimeZone
.getTimeZone(
"Asia/India");
// Creating the locale
Locale locale
= new Locale("ENGLISH",
"USA");
// Getting a display name for specified locale
String display_name
= timezone
.getDisplayName(locale);
// Display name
System.out.println("The Display name"
+ " for the locale is:"
+ display_name);
}
}
输出:
The Display name for the locale is:Greenwich Mean Time
范例2:
// Java code to illustrate getDisplayName()
import java.util.*;
public class TimeZone_Demo {
public static void main(String args[])
{
// Creating a time zone object
TimeZone timezone
= TimeZone
.getTimeZone("Australia/Sydney");
// Creating the locale
Locale locale = new Locale("ENGLISH",
"Australia");
// Getting a display name
// for specified locale
String display_name
= timezone
.getDisplayName(locale);
// Display name
System.out.println("The Display name"
+ " for the locale is:"
+ display_name);
}
}
输出:
The Display name for the locale is:
Australian Eastern Standard Time (New South Wales)