Java Code Examples for java.text.DateFormatSymbols#getLocalPatternChars()
The following examples show how to use
java.text.DateFormatSymbols#getLocalPatternChars() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateLocaleConverter.java From commons-beanutils with Apache License 2.0 | 5 votes |
/** * 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; }
Example 2
Source File: DateLocaleConverterTestCase.java From commons-beanutils with Apache License 2.0 | 4 votes |
/** * 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)); }
Example 3
Source File: DateLocaleConverter.java From commons-beanutils with Apache License 2.0 | 2 votes |
/** * 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(); }