当前位置: 首页>>代码示例>>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;未经允许,请勿转载。