Java Code Examples for java.text.DateFormat#getAvailableLocales()
The following examples show how to use
java.text.DateFormat#getAvailableLocales() .
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 Project: astor File: ExtendedMessageFormatTest.java License: GNU General Public License v2.0 | 6 votes |
/** * Test the built in date/time formats */ @Test public void testBuiltInDateTimeFormat() { final Calendar cal = Calendar.getInstance(); cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05); final Object[] args = new Object[] {cal.getTime()}; final Locale[] availableLocales = DateFormat.getAvailableLocales(); checkBuiltInFormat("1: {0,date,short}", args, availableLocales); checkBuiltInFormat("2: {0,date,medium}", args, availableLocales); checkBuiltInFormat("3: {0,date,long}", args, availableLocales); checkBuiltInFormat("4: {0,date,full}", args, availableLocales); checkBuiltInFormat("5: {0,date,d MMM yy}", args, availableLocales); checkBuiltInFormat("6: {0,time,short}", args, availableLocales); checkBuiltInFormat("7: {0,time,medium}", args, availableLocales); checkBuiltInFormat("8: {0,time,long}", args, availableLocales); checkBuiltInFormat("9: {0,time,full}", args, availableLocales); checkBuiltInFormat("10: {0,time,HH:mm}", args, availableLocales); checkBuiltInFormat("11: {0,date}", args, availableLocales); checkBuiltInFormat("12: {0,time}", args, availableLocales); }
Example 2
Source Project: astor File: ExtendedMessageFormatTest.java License: GNU General Public License v2.0 | 6 votes |
public void testOverriddenBuiltinFormat() { Calendar cal = Calendar.getInstance(); cal.set(2007, Calendar.JANUARY, 23); Object[] args = new Object[] {cal.getTime()}; Locale[] availableLocales = DateFormat.getAvailableLocales(); Map<String, ? extends FormatFactory> registry = Collections.singletonMap("date", new OverrideShortDateFormatFactory()); //check the non-overridden builtins: checkBuiltInFormat("1: {0,date}", registry, args, availableLocales); checkBuiltInFormat("2: {0,date,medium}", registry, args, availableLocales); checkBuiltInFormat("3: {0,date,long}", registry, args, availableLocales); checkBuiltInFormat("4: {0,date,full}", registry, args, availableLocales); checkBuiltInFormat("5: {0,date,d MMM yy}", registry, args, availableLocales); //check the overridden format: for (int i = -1; i < availableLocales.length; i++) { Locale locale = i < 0 ? null : availableLocales[i]; MessageFormat dateDefault = createMessageFormat("{0,date}", locale); String pattern = "{0,date,short}"; ExtendedMessageFormat dateShort = new ExtendedMessageFormat(pattern, locale, registry); assertEquals("overridden date,short format", dateDefault.format(args), dateShort.format(args)); assertEquals("overridden date,short pattern", pattern, dateShort.toPattern()); } }
Example 3
Source Project: astor File: ExtendedMessageFormatTest.java License: GNU General Public License v2.0 | 6 votes |
/** * Test the built in date/time formats */ @Test public void testBuiltInDateTimeFormat() { Calendar cal = Calendar.getInstance(); cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05); Object[] args = new Object[] {cal.getTime()}; Locale[] availableLocales = DateFormat.getAvailableLocales(); checkBuiltInFormat("1: {0,date,short}", args, availableLocales); checkBuiltInFormat("2: {0,date,medium}", args, availableLocales); checkBuiltInFormat("3: {0,date,long}", args, availableLocales); checkBuiltInFormat("4: {0,date,full}", args, availableLocales); checkBuiltInFormat("5: {0,date,d MMM yy}", args, availableLocales); checkBuiltInFormat("6: {0,time,short}", args, availableLocales); checkBuiltInFormat("7: {0,time,medium}", args, availableLocales); checkBuiltInFormat("8: {0,time,long}", args, availableLocales); checkBuiltInFormat("9: {0,time,full}", args, availableLocales); checkBuiltInFormat("10: {0,time,HH:mm}", args, availableLocales); checkBuiltInFormat("11: {0,date}", args, availableLocales); checkBuiltInFormat("12: {0,time}", args, availableLocales); }
Example 4
Source Project: openjdk-jdk9 File: CalendarRegression.java License: GNU General Public License v2.0 | 6 votes |
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); } }
Example 5
Source Project: astor File: ExtendedMessageFormatTest.java License: GNU General Public License v2.0 | 6 votes |
/** * Test the built in date/time formats */ public void testBuiltInDateTimeFormat() { Calendar cal = Calendar.getInstance(); cal.set(2007, Calendar.JANUARY, 23, 18, 33, 05); Object[] args = new Object[] {cal.getTime()}; Locale[] availableLocales = DateFormat.getAvailableLocales(); checkBuiltInFormat("1: {0,date,short}", args, availableLocales); checkBuiltInFormat("2: {0,date,medium}", args, availableLocales); checkBuiltInFormat("3: {0,date,long}", args, availableLocales); checkBuiltInFormat("4: {0,date,full}", args, availableLocales); checkBuiltInFormat("5: {0,date,d MMM yy}", args, availableLocales); checkBuiltInFormat("6: {0,time,short}", args, availableLocales); checkBuiltInFormat("7: {0,time,medium}", args, availableLocales); checkBuiltInFormat("8: {0,time,long}", args, availableLocales); checkBuiltInFormat("9: {0,time,full}", args, availableLocales); checkBuiltInFormat("10: {0,time,HH:mm}", args, availableLocales); checkBuiltInFormat("11: {0,date}", args, availableLocales); checkBuiltInFormat("12: {0,time}", args, availableLocales); }
Example 6
Source Project: threetenbp File: SimpleDateTimeFormatStyleProvider.java License: BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Locale[] getAvailableLocales() { return DateFormat.getAvailableLocales(); }
Example 7
Source Project: jdk8u_jdk File: Bug8141243.java License: GNU General Public License v2.0 | 4 votes |
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."); } }
Example 8
Source Project: openjdk-jdk8u-backup File: Bug8141243.java License: GNU General Public License v2.0 | 4 votes |
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."); } }
Example 9
Source Project: openjdk-jdk9 File: Bug8141243.java License: GNU General Public License v2.0 | 4 votes |
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."); } }
Example 10
Source Project: hottub File: Bug8141243.java License: GNU General Public License v2.0 | 4 votes |
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."); } }
Example 11
Source Project: jdk1.8-source-analysis File: Calendar.java License: Apache License 2.0 | 2 votes |
/** * 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(); }
Example 12
Source Project: jdk8u-dev-jdk File: Calendar.java License: GNU General Public License v2.0 | 2 votes |
/** * 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(); }
Example 13
Source Project: jdk-1.7-annotated File: Calendar.java License: Apache License 2.0 | 2 votes |
/** * 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(); }
Example 14
Source Project: j2objc File: Calendar.java License: Apache License 2.0 | 2 votes |
/** * 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(); }
Example 15
Source Project: jdk8u60 File: Calendar.java License: GNU General Public License v2.0 | 2 votes |
/** * 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(); }
Example 16
Source Project: openjdk-jdk8u File: Calendar.java License: GNU General Public License v2.0 | 2 votes |
/** * 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(); }
Example 17
Source Project: Bytecoder File: Calendar.java License: Apache License 2.0 | 2 votes |
/** * Returns an array of all locales for which the {@code getInstance} * methods of this class can return localized instances. * The array returned must contain at least a {@code Locale} * instance equal to {@link java.util.Locale#US Locale.US}. * * @return An array of locales for which localized * {@code Calendar} instances are available. */ public static synchronized Locale[] getAvailableLocales() { return DateFormat.getAvailableLocales(); }
Example 18
Source Project: jdk8u-jdk File: Calendar.java License: GNU General Public License v2.0 | 2 votes |
/** * 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(); }
Example 19
Source Project: jdk8u_jdk File: Calendar.java License: GNU General Public License v2.0 | 2 votes |
/** * 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(); }
Example 20
Source Project: hottub File: Calendar.java License: GNU General Public License v2.0 | 2 votes |
/** * 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(); }