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

The following examples show how to use android.icu.text.DateFormat#getDateTimeInstance() . 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: GlobalizationPreferences.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * This function can be overridden by subclasses to use different heuristics.
 * <b>It MUST return a 'safe' value,
 * one whose modification will not affect this object.</b>
 *
 * @param dateStyle
 * @param timeStyle
 * @hide draft / provisional / internal are hidden on Android
 */
protected DateFormat guessDateFormat(int dateStyle, int timeStyle) {
    DateFormat result;
    ULocale dfLocale = getAvailableLocale(TYPE_DATEFORMAT);
    if (dfLocale == null) {
        dfLocale = ULocale.ROOT;
    }
    if (timeStyle == DF_NONE) {
        result = DateFormat.getDateInstance(getCalendar(), dateStyle, dfLocale);
    } else if (dateStyle == DF_NONE) {
        result = DateFormat.getTimeInstance(getCalendar(), timeStyle, dfLocale);
    } else {
        result = DateFormat.getDateTimeInstance(getCalendar(), dateStyle, timeStyle, dfLocale);
    }
    return result;
}
 
Example 2
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestYearJump3279() {
    final long time = 1041148800000L;
    Calendar c = new GregorianCalendar();
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.US);

    c.setTimeInMillis(time);
    int year1 = c.get(Calendar.YEAR);
    
    logln("time: " + fmt.format(new Date(c.getTimeInMillis())));

    logln("setting DOW to " + c.getFirstDayOfWeek());
    c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
    logln("week: " + c.getTime());
    logln("week adjust: " + fmt.format(new Date(c.getTimeInMillis())));
    int year2 = c.get(Calendar.YEAR);
    
    if(year1 != year2) {
        errln("Error: adjusted day of week, and year jumped from " + year1 + " to " + year2);
    } else {
        logln("Year remained " + year2 + " - PASS.");
    }
}
 
Example 3
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4148168() {
        Date d = new Date(1002705212906L);
        String[] ISOPattern = {
            "''yyyy-MM-dd-hh.mm.ss.S''", "''yyyy-MM-dd-hh.mm.ss.SS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSS''", "''yyyy-MM-dd-hh.mm.ss.SSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSSSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSSSS''", "''yyyy-MM-dd-hh.mm.ss.SSS000''"};
        SimpleDateFormat aSimpleDF = (SimpleDateFormat)DateFormat.getDateTimeInstance();

        for(int i = 0; i<ISOPattern.length; i++) {
            aSimpleDF.applyPattern( ISOPattern[i] );
            logln( "Pattern = " + aSimpleDF.toPattern());
            logln( "Format = " + aSimpleDF.format(d));
        }
}
 
Example 4
Source File: DateFormatRegressionTestJ.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void Test4253490() {
    Date d = new Date(1002705212231L);

    String[] ISOPattern = {
            "''yyyy-MM-dd-hh.mm.ss.S''", 
            "''yyyy-MM-dd-hh.mm.ss.SS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSSS''", 
            "''yyyy-MM-dd-hh.mm.ss.SSSSSSS''"}; 

    SimpleDateFormat aSimpleDF = (SimpleDateFormat) DateFormat.getDateTimeInstance();
    for (int i = 0; i < ISOPattern.length; i++) {
        aSimpleDF.applyPattern(ISOPattern[i]);
        logln("Pattern = " + aSimpleDF.toPattern());
        logln("Format = " + aSimpleDF.format(d));
    }
}
 
Example 5
Source File: TestCLDRVsICU.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private SimpleDateFormat getDateFormat(ULocale locale, int dateFormat, int timeFormat) {
    if (DEBUG)
        logln("Getting date/time format for " + locale);
    if (DEBUG && "ar_EG".equals(locale.toString())) {
        logln("debug here");
    }
    DateFormat dt;
    if (dateFormat == 0) {
        dt = DateFormat.getTimeInstance(DateFormatValues[timeFormat], locale);
        if (DEBUG)
            System.out.print("getTimeInstance");
    } else if (timeFormat == 0) {
        dt = DateFormat.getDateInstance(DateFormatValues[dateFormat], locale);
        if (DEBUG)
            System.out.print("getDateInstance");
    } else {
        dt = DateFormat.getDateTimeInstance(DateFormatValues[dateFormat], DateFormatValues[timeFormat],
                locale);
        if (DEBUG)
            System.out.print("getDateTimeInstance");
    }
    if (DEBUG)
        logln("\tinput:\t" + dateFormat + ", " + timeFormat + " => " + ((SimpleDateFormat) dt).toPattern());
    return (SimpleDateFormat) dt;
}
 
Example 6
Source File: RegistrationIdViewHolder.java    From FCM-for-Mojo with GNU General Public License v3.0 5 votes vote down vote up
public RegistrationIdViewHolder(View itemView) {
    super(itemView);

    title = itemView.findViewById(android.R.id.title);
    summary = itemView.findViewById(android.R.id.summary);
    delete = itemView.findViewById(android.R.id.button1);

    delete.setOnClickListener(view -> {
        int index = getAdapterPosition();
        getAdapter().getItems().remove(index);
        getAdapter().notifyItemRemoved(index);
    });

    itemView.setOnClickListener(view -> {
        final Context context = view.getContext();
        new AlertDialog.Builder(context)
                .setMessage(Html.fromHtml(context.getString(R.string.dialog_token_message, getData().getId()), Html.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE))
                .setPositiveButton(android.R.string.copy, (dialog, which) -> ClipboardUtils.put(context, getData().getId()))
                .setNeutralButton(R.string.dialog_token_share, (dialog, which) -> context.startActivity(Intent.createChooser(new Intent(Intent.ACTION_SEND)
                                .putExtra(Intent.EXTRA_TEXT, FirebaseInstanceId.getInstance().getToken())
                                .setType("text/plain")
                        , context.getString(R.string.dialog_token_share))))
                .setNegativeButton(android.R.string.cancel, null)
                .show();
    });

    mDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());
}
 
Example 7
Source File: AstroTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
    public void TestBasics() {
        // Check that our JD computation is the same as the book's (p. 88)
        CalendarAstronomer astro = new CalendarAstronomer();
        GregorianCalendar cal3 = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US);
        DateFormat d3 = DateFormat.getDateTimeInstance(cal3, DateFormat.MEDIUM,DateFormat.MEDIUM,Locale.US);
        cal3.clear();
        cal3.set(Calendar.YEAR, 1980);
        cal3.set(Calendar.MONTH, Calendar.JULY);
        cal3.set(Calendar.DATE, 27);
        astro.setDate(cal3.getTime());
        double jd = astro.getJulianDay() - 2447891.5;
        double exp = -3444;
        if (jd == exp) {
            logln(d3.format(cal3.getTime()) + " => " + jd);
        } else {
            errln("FAIL: " + d3.format(cal3.getTime()) + " => " + jd +
                  ", expected " + exp);
        }


//        cal3.clear();
//        cal3.set(cal3.YEAR, 1990);
//        cal3.set(cal3.MONTH, Calendar.JANUARY);
//        cal3.set(cal3.DATE, 1);
//        cal3.add(cal3.DATE, -1);
//        astro.setDate(cal3.getTime());
//        astro.foo();
    }
 
Example 8
Source File: TimeZoneBoundaryTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
private static String showDate(Date d, TimeZone zone)
{
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    fmt.setTimeZone(zone);
    java.util.Calendar cal = java.util.Calendar.getInstance();
    cal.setTime(d);
    return "" + (cal.get(Calendar.YEAR) - 1900) + "/" + 
           showNN(cal.get(Calendar.MONTH) + 1) + "/" + 
           showNN(cal.get(Calendar.DAY_OF_MONTH)) + " " + 
           showNN(cal.get(Calendar.HOUR_OF_DAY)) + ":" + 
           showNN(cal.get(Calendar.MINUTE)) + " \"" + d + "\" = " +
           fmt.format(d) + " = " + d.getTime();
}
 
Example 9
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestT5683() {
    Locale[] aliasLocales = {
        new Locale("zh", "CN"),
        new Locale("zh", "TW"),
        new Locale("zh", "HK"),
        new Locale("zh", "SG"),
        new Locale("zh", "MO")
    };

    ULocale[] canonicalLocales = {
        new ULocale("zh_Hans_CN"),
        new ULocale("zh_Hant_TW"),
        new ULocale("zh_Hant_HK"),
        new ULocale("zh_Hans_SG"),
        new ULocale("zh_Hant_MO")
    };

    Date d = new Date(0);

    for (int i = 0; i < aliasLocales.length; i++) {
        DateFormat dfAlias = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, aliasLocales[i]);
        DateFormat dfCanonical = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, canonicalLocales[i]);

        String sAlias = dfAlias.format(d);
        String sCanonical = dfCanonical.format(d);

        if (!sAlias.equals(sCanonical)) {
            errln("Fail: The format result for locale " + aliasLocales[i] + " is different from the result for locale " + canonicalLocales[i]
                    + ": " + sAlias + "[" + aliasLocales[i] + "] / " + sCanonical + "[" + canonicalLocales[i] + "]");
        }
    }
}
 
Example 10
Source File: CalendarTestFmwk.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Iterates through a list of calendar <code>TestCase</code> objects and
 * makes sure that the time-to-fields and fields-to-time calculations work
 * correnctly for the values in each test case.
 */
protected void doTestCases(TestCase[] cases, Calendar cal)
{
    cal.setTimeZone(UTC);
    
    // Get a format to use for printing dates in the calendar system we're testing
    DateFormat format = DateFormat.getDateTimeInstance(cal, DateFormat.SHORT, -1, Locale.getDefault());

    final String pattern = (cal instanceof ChineseCalendar) ?
        "E MMl/dd/y G HH:mm:ss.S z" :
        "E, MM/dd/yyyy G HH:mm:ss.S z";

    ((SimpleDateFormat)format).applyPattern(pattern);

    // This format is used for printing Gregorian dates.
    DateFormat gregFormat = new SimpleDateFormat(pattern);
    gregFormat.setTimeZone(UTC);

    GregorianCalendar pureGreg = new GregorianCalendar(UTC);
    pureGreg.setGregorianChange(new Date(Long.MIN_VALUE));
    DateFormat pureGregFmt = new SimpleDateFormat("E M/d/yyyy G");
    pureGregFmt.setCalendar(pureGreg);
    
    // Now iterate through the test cases and see what happens
    for (int i = 0; i < cases.length; i++)
    {
        logln("\ntest case: " + i);
        TestCase test = cases[i];
        
        //
        // First we want to make sure that the millis -> fields calculation works
        // test.applyTime will call setTime() on the calendar object, and
        // test.fieldsEqual will retrieve all of the field values and make sure
        // that they're the same as the ones in the testcase
        //
        test.applyTime(cal);
        if (!test.fieldsEqual(cal, this)) {
            errln("Fail: (millis=>fields) " +
                  gregFormat.format(test.getTime()) + " => " +
                  format.format(cal.getTime()) +
                  ", expected " + test);
        }

        //
        // If that was OK, check the fields -> millis calculation
        // test.applyFields will set all of the calendar's fields to 
        // match those in the test case.
        //
        cal.clear();
        test.applyFields(cal);
        if (!test.equals(cal)) {
            errln("Fail: (fields=>millis) " + test + " => " +
                  pureGregFmt.format(cal.getTime()) +
                  ", expected " + pureGregFmt.format(test.getTime()));
        }
    }
}
 
Example 11
Source File: CalendarRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * DateFormat class mistakes date style and time style as follows: -
 * DateFormat.getDateTimeInstance takes date style as time style, and time
 * style as date style - If a Calendar is passed to
 * DateFormat.getDateInstance, it returns time instance - If a Calendar is
 * passed to DateFormat.getTimeInstance, it returns date instance
 */
@Test
public void TestDateFormatFactoryJ26() {
    TimeZone zone = TimeZone.getDefault();
    try {
        Locale loc = Locale.US;
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        java.util.Calendar tempcal = java.util.Calendar.getInstance();
        tempcal.set(2001, Calendar.APRIL, 5, 17, 43, 53);
        Date date = tempcal.getTime();
        Calendar cal = Calendar.getInstance(loc);
        Object[] DATA = {
            DateFormat.getDateInstance(DateFormat.SHORT, loc),
            "DateFormat.getDateInstance(DateFormat.SHORT, loc)",
            "4/5/01",

            DateFormat.getTimeInstance(DateFormat.SHORT, loc),
            "DateFormat.getTimeInstance(DateFormat.SHORT, loc)",
            "5:43 PM",

            DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, loc),
            "DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT, loc)",
            "Thursday, April 5, 2001 at 5:43 PM",

            DateFormat.getDateInstance(cal, DateFormat.SHORT, loc),
            "DateFormat.getDateInstance(cal, DateFormat.SHORT, loc)",
            "4/5/01",

            DateFormat.getTimeInstance(cal, DateFormat.SHORT, loc),
            "DateFormat.getTimeInstance(cal, DateFormat.SHORT, loc)",
            "5:43 PM",

            DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.SHORT, loc),
            "DateFormat.getDateTimeInstance(cal, DateFormat.FULL, DateFormat.SHORT, loc)",
            "Thursday, April 5, 2001 at 5:43 PM",
        
            cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.FULL, loc),
            "cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.FULL, loc)",
            "4/5/01, 5:43:53 PM Pacific Daylight Time",

            cal.getDateTimeFormat(DateFormat.FULL, DateFormat.SHORT, loc),
            "cal.getDateTimeFormat(DateFormat.FULL, DateFormat.SHORT, loc)",
            "Thursday, April 5, 2001 at 5:43 PM",
        };
        for (int i=0; i<DATA.length; i+=3) {
            DateFormat df = (DateFormat) DATA[i];
            String desc = (String) DATA[i+1];
            String exp = (String) DATA[i+2];
            String got = df.format(date);
            if (got.equals(exp)) {
                logln("Ok: " + desc + " => " + got);
            } else {
                errln("FAIL: " + desc + " => " + got + ", expected " + exp);
            }
        }
    } finally {
        TimeZone.setDefault(zone);
    }
}
 
Example 12
Source File: TimeZoneBoundaryTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
void findDaylightBoundaryUsingTimeZone(Date d, boolean startsInDST,
                                       long expectedBoundary, TimeZone tz)
{
    // Given a date with a year start, find the Daylight onset
    // and end.  The given date should be 1/1/xx in some year.

    // Use a binary search, assuming that we have a Standard
    // time at the midpoint.
    long min = d.getTime();
    long max = min + SIX_MONTHS;

    if (tz.inDaylightTime(d) != startsInDST)
    {
        errln("FAIL: " + tz.getID() + " inDaylightTime(" +
              d + ") != " + startsInDST);
        startsInDST = !startsInDST; // Flip over; find the apparent value
    }

    if (tz.inDaylightTime(new Date(max)) == startsInDST)
    {
        errln("FAIL: " + tz.getID() + " inDaylightTime(" +
              (new Date(max)) + ") != " + (!startsInDST));
        return;
    }

    while ((max - min) >  INTERVAL)
    {
        long mid = (min + max) >> 1;
        boolean isIn = tz.inDaylightTime(new Date(mid));
        if (isIn == startsInDST)
        {
            min = mid;
        }
        else
        {
            max = mid;
        }
    }

    logln(tz.getID() + " Before: " + showDate(min, tz));
    logln(tz.getID() + " After:  " + showDate(max, tz));

    long mindelta = expectedBoundary - min;
    // not used long maxdelta = max - expectedBoundary; 
    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    fmt.setTimeZone(tz);
    if (mindelta >= 0 && mindelta <= INTERVAL &&
        mindelta >= 0 && mindelta <= INTERVAL)
        logln("PASS: Expected boundary at " + expectedBoundary + " = " + fmt.format(new Date(expectedBoundary)));
    else
        errln("FAIL: Expected boundary at " + expectedBoundary + " = " + fmt.format(new Date(expectedBoundary)));
}
 
Example 13
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @bug 4052408
 */
@Test
public void Test4052408() {

    DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US); 
    Calendar cal = Calendar.getInstance();
    cal.clear();
    cal.set(97 + 1900, Calendar.MAY, 3, 8, 55);
    Date dt = cal.getTime();
    String str = fmt.format(dt);
    logln(str);
    
    if (!str.equals("5/3/97, 8:55 AM"))
        errln("Fail: Test broken; Want 5/3/97, 8:55 AM Got " + str);

    String expected[] = {
        "", //"ERA_FIELD",
        "97", //"YEAR_FIELD",
        "5", //"MONTH_FIELD",
        "3", //"DATE_FIELD",
        "", //"HOUR_OF_DAY1_FIELD",
        "", //"HOUR_OF_DAY0_FIELD",
        "55", //"MINUTE_FIELD",
        "", //"SECOND_FIELD",
        "", //"MILLISECOND_FIELD",
        "", //"DAY_OF_WEEK_FIELD",
        "", //"DAY_OF_YEAR_FIELD",
        "", //"DAY_OF_WEEK_IN_MONTH_FIELD",
        "", //"WEEK_OF_YEAR_FIELD",
        "", //"WEEK_OF_MONTH_FIELD",
        "AM", //"AM_PM_FIELD",
        "8", //"HOUR1_FIELD",
        "", //"HOUR0_FIELD",
        "" //"TIMEZONE_FIELD"
        };        
    String fieldNames[] = {
            "ERA_FIELD", 
            "YEAR_FIELD", 
            "MONTH_FIELD", 
            "DATE_FIELD", 
            "HOUR_OF_DAY1_FIELD", 
            "HOUR_OF_DAY0_FIELD", 
            "MINUTE_FIELD", 
            "SECOND_FIELD", 
            "MILLISECOND_FIELD", 
            "DAY_OF_WEEK_FIELD", 
            "DAY_OF_YEAR_FIELD", 
            "DAY_OF_WEEK_IN_MONTH_FIELD", 
            "WEEK_OF_YEAR_FIELD", 
            "WEEK_OF_MONTH_FIELD", 
            "AM_PM_FIELD", 
            "HOUR1_FIELD", 
            "HOUR0_FIELD", 
            "TIMEZONE_FIELD"}; 

    boolean pass = true;
    for (int i = 0; i <= 17; ++i) {
        FieldPosition pos = new FieldPosition(i);
        StringBuffer buf = new StringBuffer("");
        fmt.format(dt, buf, pos);
        //char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()];
        String dst = buf.substring(pos.getBeginIndex(), pos.getEndIndex());
        str = dst;
        log(i + ": " + fieldNames[i] + ", \"" + str + "\", "
                + pos.getBeginIndex() + ", " + pos.getEndIndex()); 
        String exp = expected[i];
        if ((exp.length() == 0 && str.length() == 0) || str.equals(exp))
            logln(" ok");
        else {
            logln(" expected " + exp);
            pass = false;
        }
    }
    if (!pass)
        errln("Fail: FieldPosition not set right by DateFormat");
}
 
Example 14
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @bug 4065240
 */
@Test
public void Test4065240() {
    Date curDate;
    DateFormat shortdate, fulldate;
    String strShortDate, strFullDate;
    Locale saveLocale = Locale.getDefault();
    TimeZone saveZone = TimeZone.getDefault();

    try {
        Locale curLocale = new Locale("de", "DE");
        Locale.setDefault(curLocale);
        // {sfb} adoptDefault instead of setDefault
        //TimeZone.setDefault(TimeZone.createTimeZone("EST"));
        TimeZone.setDefault(TimeZone.getTimeZone("EST"));
        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(98 + 1900, 0, 1);
        curDate = cal.getTime();
        shortdate = DateFormat.getDateInstance(DateFormat.SHORT);
        fulldate = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
        strShortDate = "The current date (short form) is ";
        String temp;
        temp = shortdate.format(curDate);
        strShortDate += temp;
        strFullDate = "The current date (long form) is ";
        String temp2 = fulldate.format(curDate);
        strFullDate += temp2;

        logln(strShortDate);
        logln(strFullDate);

        // {sfb} What to do with resource bundle stuff?????

        // Check to see if the resource is present; if not, we can't test
        //ResourceBundle bundle = //The variable is never used
        //    ICULocaleData.getBundle("DateFormatZoneData", curLocale); 

        // {sfb} API change to ResourceBundle -- add getLocale()
        /*if (bundle.getLocale().getLanguage().equals("de")) {
            // UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
            if (!strFullDate.endsWith("GMT-05:00"))
                errln("Fail: Want GMT-05:00");
        } else {
            logln("*** TEST COULD NOT BE COMPLETED BECAUSE DateFormatZoneData ***");
            logln("*** FOR LOCALE de OR de_DE IS MISSING ***");
        }*/
    } catch (Exception e) {
        logln(e.getMessage());
    } finally {
        Locale.setDefault(saveLocale);
        TimeZone.setDefault(saveZone);
    }

}
 
Example 15
Source File: DateFormatRegressionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * @bug 4106807
 */
@Test
public void Test4106807() {
    Date dt;
    DateFormat df = DateFormat.getDateTimeInstance();

    SimpleDateFormat sdfs[] = {
            new SimpleDateFormat("yyyyMMddHHmmss"), 
            new SimpleDateFormat("yyyyMMddHHmmss'Z'"), 
            new SimpleDateFormat("yyyyMMddHHmmss''"), 
            new SimpleDateFormat("yyyyMMddHHmmss'a''a'"), 
            new SimpleDateFormat("yyyyMMddHHmmss %")}; 
    String strings[] = {
            "19980211140000", 
            "19980211140000", 
            "19980211140000", 
            "19980211140000a", 
            "19980211140000 "}; 
    GregorianCalendar gc = new GregorianCalendar();
    TimeZone timeZone = TimeZone.getDefault();
    TimeZone gmt = (TimeZone) timeZone.clone();
    gmt.setRawOffset(0);
    for (int i = 0; i < 5; i++) {
        SimpleDateFormat format = sdfs[i];
        String dateString = strings[i];
        try {
            format.setTimeZone(gmt);
            dt = format.parse(dateString);
            // {sfb} some of these parses will fail purposely

            StringBuffer fmtd = new StringBuffer("");
            FieldPosition pos = new FieldPosition(0);
            fmtd = df.format(dt, fmtd, pos);
            logln(fmtd.toString());
            //logln(df.format(dt)); 
            gc.setTime(dt);
            logln("" + gc.get(Calendar.ZONE_OFFSET));
            StringBuffer s = new StringBuffer("");
            s = format.format(dt, s, pos);
            logln(s.toString());
        } catch (ParseException e) {
            logln("No way Jose");
        }
    }
}