java.text.DateFormatSymbols#getLocalPatternChars ( )源码实例Demo

下面列出了java.text.DateFormatSymbols#getLocalPatternChars ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: commons-beanutils   文件: DateLocaleConverter.java
/**
  * Convert a pattern from a localized format to the default format.
  *
  * @param locale   The locale
  * @param localizedPattern The pattern in 'local' symbol format
  * @return pattern in 'default' symbol format
  */
 private String convertLocalizedPattern(final String localizedPattern, final Locale locale) {

     if (localizedPattern == null) {
        return null;
     }

     // Note that this is a little obtuse.
     // However, it is the best way that anyone can come up with
     // that works with some 1.4 series JVM.

     // Get the symbols for the localized pattern
     final DateFormatSymbols localizedSymbols = new DateFormatSymbols(locale);
     final String localChars = localizedSymbols.getLocalPatternChars();

     if (DEFAULT_PATTERN_CHARS.equals(localChars)) {
         return localizedPattern;
     }

     // Convert the localized pattern to default
     String convertedPattern = null;
     try {
         convertedPattern = convertPattern(localizedPattern,
                                            localChars,
                                            DEFAULT_PATTERN_CHARS);
     } catch (final Exception ex) {
         log.debug("Converting pattern '" + localizedPattern + "' for " + locale, ex);
     }
     return convertedPattern;
}
 
/**
     * Set up instance variables required by this test case.
     */
    @Override
    public void setUp() throws Exception {

        super.setUp();

        final String version = System.getProperty("java.specification.version");
        log.debug("JDK Version "+version);

        try {
            final SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
            expectedValue      = format.parse("20041001");
            defaultValue       = format.parse("19670316");
        } catch (final Exception ex) {
            log.error("Error creating expected/default dates", ex);
        }

        // Default Locale (Use US)
        defaultLocale           = Locale.US;
        defaultDatePattern      = "d MMMM yyyy";
        defaultDateValue        = "1 October 2004";
        defaultShortDateValue   = "10/01/04";

        // Use German Locale
//        localizedLocale         = Locale.GERMAN;  // N.B. doesn't work for dates
//        localizedLocale         = Locale.GERMANY; // N.B. doesn't work for dates
        localizedLocale         = new Locale("de", "AT"); // Austria/German works
        localizedDatePattern    = "t MMMM uuuu";
        localizedDateValue      = "1 Oktober 2004";
        localizedShortDateValue = "01.10.04";

        // Test whether the "local pattern characters" are what we
        // are expecting - Locale.GERMAN and Locale.GERMANY, Locale.FRENCH all
        // returned the standard "English" pattern characters on my machine
        // for JDK 1.4 (JDK 1.3 was OK). The Austria/German locale was OK though
        final String expectedChars = "GuMtkHmsSEDFwWahKzZ";
        final DateFormatSymbols localizedSymbols = new DateFormatSymbols(localizedLocale);
        final String localChars    = localizedSymbols.getLocalPatternChars();

        // different JDK versions seem to have different numbers of pattern characters
        final int lth = localChars.length() > expectedChars.length() ? expectedChars.length() :
                Math.min(localChars.length(), expectedChars.length());
        validLocalDateSymbols = expectedChars.substring(0, lth).equals(localChars.substring(0, lth));

    }
 
源代码3 项目: commons-beanutils   文件: DateLocaleConverter.java
/**
 * This method is called at class initialization time to define the
 * value for constant member DEFAULT_PATTERN_CHARS. All other methods needing
 * this data should just read that constant.
 */
private static String initDefaultChars() {
    final DateFormatSymbols defaultSymbols = new DateFormatSymbols(Locale.US);
    return defaultSymbols.getLocalPatternChars();
}