import com.ibm.icu.text.DateFormat; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.ULocale; ... ULocale locale = new ULocale("fa_IR@calendar=persian"); Calendar calendar = Calendar.getInstance(locale); DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, locale); System.out.println(df.format(calendar));
ULocale uLocale = ULocale.forLanguageTag("pl-PL"); ResourceBundle resources = ResourceBundle.getBundle( "path.to.messages", uLocale.toLocale()); PluralRules pluralRules = PluralRules.forLocale(uLocale); double[] numbers = { 0, 1, 1.5, 2, 2.5, 3, 4, 5, 5.5, 11, 12, 23 }; for (double number : numbers) { String resourceKey = "some.message.plural_form." + pluralRules.select(number); String message = "!" + resourceKey + "!"; try { message = resources.getString(resourceKey); System.out.println(format(message, uLocale, number)); } catch (MissingResourceException e) { // Log this } }
@Implementation(maxSdk = LOLLIPOP_MR1) @SuppressWarnings("JdkObsolete") public static String formatDateInterval(long address, long fromDate, long toDate) { StringBuffer buffer = new StringBuffer(); FieldPosition pos = new FieldPosition(0); INTERVAL_CACHE.get(address).format(new com.ibm.icu.util.DateInterval(fromDate, toDate), buffer, pos); return buffer.toString(); } }
/** * This function can be overridden by subclasses to use different heuristics * * @draft ICU 3.6 * @provisional This API might change or be removed in a future release. */ protected Currency guessCurrency() { return Currency.getInstance(new ULocale("und-" + getTerritory())); }
/** * Constructs a Calendar with the default time zone * and locale. * @see TimeZone#getDefault * @stable ICU 2.0 */ protected Calendar() { this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); }
/** * Constructs a <code>HebrewCalendar</code> with the given date set * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar(Date date) { super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); }
/** * Constructs a <code>IndianCalendar</code> with the given date set * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar(Date date) { super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); }
/** * Constructs an <code>IslamicCalendar</code> with the given date set * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. * @see Category#FORMAT * @stable ICU 2.8 */ public IslamicCalendar(Date date) { super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); }
/** * Construct a <code>ChineseCalendar</code> with the give date set in the default time zone * with the default locale. * @param date The date to which the new calendar is set. * @stable ICU 4.0 */ public ChineseCalendar(Date date) { this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT), CHINESE_EPOCH_YEAR, CHINA_ZONE); setTime(date); }
/** * Convenience method: Get the best match for a LanguagePriorityList * * @param languageList String form of language priority list * @return best matching language code * @stable ICU 4.4 */ public ULocale getBestMatch(String languageList) { return getBestMatch(LocalePriorityList.add(languageList).build()); }
/** * Constructs a <code>CECalendar</code> with the given date set * in the default time zone with the default <code>FORMAT</code> locale. * * @param date The date to which the new calendar is set. */ protected CECalendar(Date date) { super(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); this.setTime(date); }
/** * Returns a calendar using the default time zone and specified locale. * @param aLocale the locale for the week data * @return a Calendar. * @stable ICU 2.0 */ public static Calendar getInstance(Locale aLocale) { return getInstanceInternal(null, ULocale.forLocale(aLocale)); }
public ICUDataTable(String path, ULocale locale, boolean nullIfNotFound) { super(nullIfNotFound); this.bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance( path, locale.getBaseName()); }
private static long getTransitionTime(TimeZoneTransition tzt, boolean local, int NonExistingTimeOpt, int DuplicatedTimeOpt) { long time = tzt.getTime(); if (local) { time += getLocalDelta(tzt.getFrom().getRawOffset(), tzt.getFrom().getDSTSavings(), tzt.getTo().getRawOffset(), tzt.getTo().getDSTSavings(), NonExistingTimeOpt, DuplicatedTimeOpt); } return time; }
/** * Returns the size of paper used in the locale. The paper sizes returned are always in * <em>milli-meters</em>. * @param locale The locale for which the measurement system to be retrieved. * @return The paper size used in the locale * @stable ICU 3.0 */ public static final PaperSize getPaperSize(ULocale locale){ UResourceBundle obj = measurementTypeBundleForLocale(locale, PAPER_SIZE); int[] size = obj.getIntVector(); return new PaperSize(size[0], size[1]); }
/** * TimeZone API * Returns the amount of time to be added to local standard time * to get local wall clock time. */ @Override public int getDSTSavings() { if (finalZone != null){ return finalZone.getDSTSavings(); } return super.getDSTSavings(); }
/** * Constructs a default <code>HebrewCalendar</code> using the current time * in the default time zone with the default <code>FORMAT</code> locale. * @see Category#FORMAT * @stable ICU 2.8 */ public HebrewCalendar() { this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); }
/** * Constructs a Calendar with the default time zone * and the default <code>FORMAT</code> locale. * @see TimeZone#getDefault * @see Category#FORMAT * @stable ICU 2.0 */ protected Calendar() { this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); }
/** * Construct a <code>ChineseCalendar</code> with the default time zone and locale. * @stable ICU 2.8 */ public ChineseCalendar() { this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT), CHINESE_EPOCH_YEAR, CHINA_ZONE); }
/** * Constructs a <code>IndianCalendar</code> using the current time * in the default time zone with the default <code>FORMAT</code> locale. * @see Category#FORMAT * @stable ICU 3.8 */ public IndianCalendar() { this(TimeZone.getDefault(), ULocale.getDefault(Category.FORMAT)); }