访问量: 10 次浏览
Java 中 TimeZone 类的 getDisplayName(Locale locale) 方法用于获得该 TimeZone 的一个特定名称,该名称在用户传递的指定 Locale 中容易被用户理解。该名称适合于演示和显示的目的。
public final String getDisplayName(Locale locale)
该方法需要一个 Locale 对象类型的参数 locale,并且指的是要提供显示名称的 Locale。
该方法返回 TimeZone 在指定 Locale 中的显示名称。
下面的程序说明了 TimeZone 的 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
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)