本文整理匯總了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();
}