Java Code Examples for android.icu.text.DateFormat#getInstance()

The following examples show how to use android.icu.text.DateFormat#getInstance() . 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 File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * @bug 4071441
 */
@Test
public void Test4071441() {
    DateFormat fmtA = DateFormat.getInstance();
    DateFormat fmtB = DateFormat.getInstance();

    // {sfb} Is it OK to cast away const here?
    Calendar calA = fmtA.getCalendar();
    Calendar calB = fmtB.getCalendar();
    calA.clear();
    calA.set(1900, 0 ,0);
    calB.clear();
    calB.set(1900, 0, 0);
    if (!calA.equals(calB))
        errln("Fail: Can't complete test; Calendar instances unequal");
    if (!fmtA.equals(fmtB))
        errln("Fail: DateFormat unequal when Calendars equal");
    calB.clear();
    calB.set(1961, Calendar.DECEMBER, 25);
    if (calA.equals(calB))
        errln("Fail: Can't complete test; Calendar instances equal");
    if (!fmtA.equals(fmtB))
        errln("Fail: DateFormat unequal when Calendars equivalent");
    logln("DateFormat.equals ok");
}
 
Example 2
Source File: IntlTestDateFormatAPI.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
    public void TestEquals()
    {
        // Create two objects at different system times
        DateFormat a = DateFormat.getInstance();
        Date start = Calendar.getInstance().getTime();
        while (true) {
            // changed to remove compiler warnings.
            if (!start.equals(Calendar.getInstance().getTime())) {
                break; // Wait for time to change
            }
        }
        DateFormat b = DateFormat.getInstance();

        if (!(a.equals(b)))
            errln("FAIL: DateFormat objects created at different times are unequal.");

        // Why has this test been disabled??? - aliu
//        if (b instanceof SimpleDateFormat)
//        {
//            //double ONE_YEAR = 365*24*60*60*1000.0; //The variable is never used
//            try {
//                ((SimpleDateFormat)b).setTwoDigitStartDate(start.getTime() + 50*ONE_YEAR);
//                if (a.equals(b))
//                    errln("FAIL: DateFormat objects with different two digit start dates are equal.");
//            }
//            catch (Exception e) {
//                errln("FAIL: setTwoDigitStartDate failed.");
//            }
//        }
    }
 
Example 3
Source File: IntlTestDateFormat.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Before
public void init() throws Exception {
    fFormat = DateFormat.getInstance();
}