public static void addPatternExample() { System.out.println("========================================================================"); System.out.println(" addPatternExample()"); System.out.println(); System.out.println(" Use addPattern API to add new '. von' to existing pattern"); System.out.println("========================================================================"); // ---addPatternExample Date date = new GregorianCalendar(1999, 9, 13, 23, 58, 59).getTime(); ULocale locale = ULocale.FRANCE; // Create an DateTimePatternGenerator instance for the given locale DateTimePatternGenerator gen = DateTimePatternGenerator.getInstance(locale); SimpleDateFormat format = new SimpleDateFormat(gen.getBestPattern("MMMMddHmm"), locale); DateTimePatternGenerator.PatternInfo returnInfo = new DateTimePatternGenerator.PatternInfo(); // Add '. von' to the existing pattern gen.addPattern("dd'. von' MMMM", true, returnInfo); // Apply the new pattern format.applyPattern(gen.getBestPattern("MMMMddHmm")); System.out.println("New Pattern for FRENCH: " + format.toPattern()); System.out.println("Date Time in new Pattern: " + format.format(date)); /** * output of the sample code: * ************************************************************************************************* * New Pattern for FRENCH: dd. 'von' MMMM HH:mm Date Time in new Pattern: 13. von octobre 23:58 * * <p>*********************************************************************************************** */ // ---addPatternExample }
public static void replaceFieldTypesExample() { // Use repalceFieldTypes API to replace zone 'zzzz' with 'vvvv' System.out.println("========================================================================"); System.out.println(" replaceFieldTypeExample()"); System.out.println(); System.out.println(" Use replaceFieldTypes API to replace zone 'zzzz' with 'vvvv"); System.out.println("========================================================================"); // ---replaceFieldTypesExample Date date = new GregorianCalendar(1999, 9, 13, 23, 58, 59).getTime(); TimeZone zone = TimeZone.getTimeZone("Europe/Paris"); ULocale locale = ULocale.FRANCE; DateTimePatternGenerator gen = DateTimePatternGenerator.getInstance(locale); SimpleDateFormat format = new SimpleDateFormat("EEEE d MMMM y HH:mm:ss zzzz", locale); format.setTimeZone(zone); String pattern = format.toPattern(); System.out.println("Pattern before replacement:"); System.out.println(pattern); System.out.println("Date/Time format in fr_FR:"); System.out.println(format.format(date)); // Replace zone "zzzz" in the pattern with "vvvv" String newPattern = gen.replaceFieldTypes(pattern, "vvvv"); // Apply the new pattern format.applyPattern(newPattern); System.out.println("Pattern after replacement:"); System.out.println(newPattern); System.out.println("Date/Time format in fr_FR:"); System.out.println(format.format(date)); /** * output of the sample code: * ************************************************************************************************** * Pattern before replacement: EEEE d MMMM y HH:mm:ss zzzz Date/Time format in fr_FR: jeudi 14 * octobre 1999 05:58:59 heure avancée d’Europe centrale Pattern after replacement: EEEE d MMMM * y HH:mm:ss vvvv Date/Time format in fr_FR: jeudi 14 octobre 1999 05:58:59 heure de l’Europe * centrale * * <p>************************************************************************************************ */ // ---replaceFieldTypesExample }