Search in sources :

Example 76 with SimpleDateFormat

use of android.icu.text.SimpleDateFormat in project j2objc by google.

the class TestMessageFormat method TestSetFormat.

@Test
public void TestSetFormat() {
    MessageFormat ms = new MessageFormat("{number} {date}", ULocale.ENGLISH);
    final DecimalFormat decimalFormat = new DecimalFormat("000.000", DecimalFormatSymbols.getInstance(ULocale.ENGLISH));
    ms.setFormatByArgumentName("number", decimalFormat);
    final SimpleDateFormat dateFormat = new SimpleDateFormat("'year:'yy 'month:'MM 'day:'dd");
    dateFormat.setTimeZone(TimeZone.getTimeZone("Etc/GMT"));
    ms.setFormatByArgumentName("date", dateFormat);
    Map map = new HashMap();
    map.put("number", new Integer(1234));
    map.put("date", new Date(0, 0, 0));
    String result = ms.format(map);
    assertEquals("setFormatByArgumentName", "1234.000 year:99 month:12 day:31", result);
    Set formatNames = ms.getArgumentNames();
    assertEquals("Format Names match", formatNames, map.keySet());
    assertEquals("Decimal", decimalFormat, ms.getFormatByArgumentName("number"));
    assertEquals("Date", dateFormat, ms.getFormatByArgumentName("date"));
}
Also used : Set(java.util.Set) MessageFormat(android.icu.text.MessageFormat) HashMap(java.util.HashMap) DecimalFormat(android.icu.text.DecimalFormat) AttributedString(java.text.AttributedString) SimpleDateFormat(android.icu.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Date(java.util.Date) Test(org.junit.Test)

Example 77 with SimpleDateFormat

use of android.icu.text.SimpleDateFormat in project android_frameworks_base by AOSPA.

the class DatePickerCalendarDelegate method onPopulateAccessibilityEvent.

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (mAccessibilityEventFormat == null) {
        final String pattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "EMMMMdy");
        mAccessibilityEventFormat = new SimpleDateFormat(pattern);
    }
    final CharSequence text = mAccessibilityEventFormat.format(mCurrentDate.getTime());
    event.getText().add(text);
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 78 with SimpleDateFormat

use of android.icu.text.SimpleDateFormat in project android_frameworks_base by ResurrectionRemix.

the class DatePickerCalendarDelegate method onPopulateAccessibilityEvent.

@Override
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (mAccessibilityEventFormat == null) {
        final String pattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "EMMMMdy");
        mAccessibilityEventFormat = new SimpleDateFormat(pattern);
    }
    final CharSequence text = mAccessibilityEventFormat.format(mCurrentDate.getTime());
    event.getText().add(text);
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 79 with SimpleDateFormat

use of android.icu.text.SimpleDateFormat in project android_frameworks_base by ResurrectionRemix.

the class SimpleMonthView method updateMonthYearLabel.

private void updateMonthYearLabel() {
    final String format = DateFormat.getBestDateTimePattern(mLocale, MONTH_YEAR_FORMAT);
    final SimpleDateFormat formatter = new SimpleDateFormat(format, mLocale);
    formatter.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
    mMonthYearLabel = formatter.format(mCalendar.getTime());
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Example 80 with SimpleDateFormat

use of android.icu.text.SimpleDateFormat in project android_frameworks_base by crdroidandroid.

the class DatePickerCalendarDelegate method onLocaleChanged.

@Override
protected void onLocaleChanged(Locale locale) {
    final TextView headerYear = mHeaderYear;
    if (headerYear == null) {
        // again later after everything has been set up.
        return;
    }
    // Update the date formatter.
    final String datePattern = DateFormat.getBestDateTimePattern(locale, "EMMMd");
    mMonthDayFormat = new SimpleDateFormat(datePattern, locale);
    mMonthDayFormat.setContext(DisplayContext.CAPITALIZATION_FOR_STANDALONE);
    mYearFormat = new SimpleDateFormat("y", locale);
    // Clear out the lazily-initialized accessibility event formatter.
    mAccessibilityEventFormat = null;
    // Update the header text.
    onCurrentDateChanged(false);
}
Also used : SimpleDateFormat(android.icu.text.SimpleDateFormat)

Aggregations

SimpleDateFormat (android.icu.text.SimpleDateFormat)153 Test (org.junit.Test)113 Date (java.util.Date)103 GregorianCalendar (android.icu.util.GregorianCalendar)59 Calendar (android.icu.util.Calendar)53 ParseException (java.text.ParseException)42 DateFormat (android.icu.text.DateFormat)41 JapaneseCalendar (android.icu.util.JapaneseCalendar)41 ULocale (android.icu.util.ULocale)40 IslamicCalendar (android.icu.util.IslamicCalendar)37 ParsePosition (java.text.ParsePosition)36 FieldPosition (java.text.FieldPosition)29 ChineseCalendar (android.icu.util.ChineseCalendar)27 TimeZone (android.icu.util.TimeZone)27 BuddhistCalendar (android.icu.util.BuddhistCalendar)25 ChineseDateFormat (android.icu.text.ChineseDateFormat)21 HebrewCalendar (android.icu.util.HebrewCalendar)21 IOException (java.io.IOException)19 SimpleTimeZone (android.icu.util.SimpleTimeZone)16 Locale (java.util.Locale)14