本文整理汇总了Java中java.text.DateFormat.getAvailableLocales方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.getAvailableLocales方法的具体用法?Java DateFormat.getAvailableLocales怎么用?Java DateFormat.getAvailableLocales使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.text.DateFormat
的用法示例。
在下文中一共展示了DateFormat.getAvailableLocales方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Test4106136
import java.text.DateFormat; //导入方法依赖的package包/类
public void Test4106136() {
Locale saveLocale = Locale.getDefault();
try {
Locale[] locales = {Locale.CHINESE, Locale.CHINA};
for (int i = 0; i < locales.length; ++i) {
Locale.setDefault(locales[i]);
int[] n = {
getAvailableLocales().length,
DateFormat.getAvailableLocales().length,
NumberFormat.getAvailableLocales().length};
for (int j = 0; j < n.length; ++j) {
if (n[j] == 0) {
errln("Fail: No locales for " + locales[i]);
}
}
}
} finally {
Locale.setDefault(saveLocale);
}
}
示例2: main
import java.text.DateFormat; //导入方法依赖的package包/类
public static void main(String[] args) {
TimeZone UTC = TimeZone.getTimeZone("UTC");
TimeZone initTz = TimeZone.getDefault();
List<String> errors = new ArrayList<>();
try {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
for (Locale locale : DateFormat.getAvailableLocales()) {
// exclude any locales which localize "UTC".
String utc = UTC.getDisplayName(false, SHORT, locale);
if (!"UTC".equals(utc)) {
System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
continue;
}
SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
try {
Date date = fmt.parse("UTC");
// Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
errors.add("timezone: " + fmt.getTimeZone().getID()
+ ", locale: " + locale);
}
} catch (ParseException e) {
errors.add("parse exception: " + e + ", locale: " + locale);
}
}
} finally {
// Restore the default time zone
TimeZone.setDefault(initTz);
}
if (!errors.isEmpty()) {
System.out.println("Got unexpected results:");
for (String s : errors) {
System.out.println(" " + s);
}
throw new RuntimeException("Test failed.");
} else {
System.out.println("Test passed.");
}
}
示例3: getAvailableLocales
import java.text.DateFormat; //导入方法依赖的package包/类
/**
* Returns an array of all locales for which the <code>getInstance</code>
* methods of this class can return localized instances.
* The array returned must contain at least a <code>Locale</code>
* instance equal to {@link java.util.Locale#US Locale.US}.
*
* @return An array of locales for which localized
* <code>Calendar</code> instances are available.
*/
public static synchronized Locale[] getAvailableLocales()
{
return DateFormat.getAvailableLocales();
}