Example usage for java.text DateFormatSymbols getLocalPatternChars

List of usage examples for java.text DateFormatSymbols getLocalPatternChars

Introduction

In this page you can find the example usage for java.text DateFormatSymbols getLocalPatternChars.

Prototype

public String getLocalPatternChars() 

Source Link

Document

Gets localized date-time pattern characters.

Usage

From source file:javadz.beanutils.locale.converters.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.
 *//*from   ww  w. j av a2 s .  c o m*/
private static String initDefaultChars() {
    DateFormatSymbols defaultSymbols = new DateFormatSymbols(Locale.US);
    return defaultSymbols.getLocalPatternChars();
}

From source file:javadz.beanutils.locale.converters.DateLocaleConverter.java

/**
 * Convert a pattern from a localized format to the default format.
 *
 * @param locale   The locale//from   w w w.  j av a 2 s. c o m
 * @param localizedPattern The pattern in 'local' symbol format
 * @return pattern in 'default' symbol format
 */
private String convertLocalizedPattern(String localizedPattern, 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
    DateFormatSymbols localizedSymbols = new DateFormatSymbols(locale);
    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 (Exception ex) {
        log.debug("Converting pattern '" + localizedPattern + "' for " + locale, ex);
    }
    return convertedPattern;
}