當前位置: 首頁>>代碼示例>>Java>>正文


Java DateFormat.getAvailableLocales方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:CalendarRegression.java

示例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.");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:42,代碼來源:Bug8141243.java

示例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();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:14,代碼來源:Calendar.java


注:本文中的java.text.DateFormat.getAvailableLocales方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。