// 第三步创建对象 privatestatic Calendar createCalendar(TimeZone zone,Locale aLocale){ CalendarProviderprovider= LocaleProviderAdapter.getAdapter(CalendarProvider.class, aLocale) .getCalendarProvider(); if (provider != null) { try { return provider.getInstance(zone, aLocale); } catch (IllegalArgumentException iae) { // fall back to the default instantiation } }
Calendarcal=null;
if (aLocale.hasExtensions()) { Stringcaltype= aLocale.getUnicodeLocaleType("ca"); if (caltype != null) { switch (caltype) { case"buddhist": cal = newBuddhistCalendar(zone, aLocale); break; case"japanese": cal = newJapaneseImperialCalendar(zone, aLocale); break; case"gregory": cal = newGregorianCalendar(zone, aLocale); break; } } } if (cal == null) { // If no known calendar type is explicitly specified, // perform the traditional way to create a Calendar: // create a BuddhistCalendar for th_TH locale, // a JapaneseImperialCalendar for ja_JP_JP locale, or // a GregorianCalendar for any other locales. // NOTE: The language, country and variant strings are interned. if (aLocale.getLanguage() == "th" && aLocale.getCountry() == "TH") { cal = newBuddhistCalendar(zone, aLocale); } elseif (aLocale.getVariant() == "JP" && aLocale.getLanguage() == "ja" && aLocale.getCountry() == "JP") { cal = newJapaneseImperialCalendar(zone, aLocale); } else { cal = newGregorianCalendar(zone, aLocale); } } return cal; }