Skip to content Skip to sidebar Skip to footer

Android Simpledateformat Fails To Parse Datetime (works Fine On Sun 1.6 Jre)

Any ideas why the followng fails on Android 2.2... java.text.ParseException: Unparseable date: 2011-02-16 11:38:03.328 UTC ...while it works fine on a sun JRE 1.6 ? DateFormat dat

Solution 1:

Use this instead

DateFormatdateFormat=newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");

Solution 2:

I have a workaround now:

DateFormatdateFormat=newSimpleDateFormat("yyyy-MM-dd HH:mm:ss.S 'UTC'");
try
{
  Datedate= dateFormat.parse("2011-02-16 11:38:03.328 UTC");
}
catch (ParseException e)
{
  e.printStackTrace();
}

This allows me to at least parse the date in Android 2.2. My application has been modified to try "yyyy-MM-dd HH:mm:ss.S 'UTC'" and then try "yyyy-MM-dd HH:mm:ss.S z" if the first parse fails

Solution 3:

Solution 4:

I have copied this code and got casting exception...

try this code of mine

java.text.SimpleDateFormatformat=newSimpleDateFormat(
                    "dd-MM-yyyy");
            java.util.Calendarcal= Calendar.getInstance(newSimpleTimeZone(0,
                    "GMT"));
            format.setCalendar(cal);
java.util.Datedate=null;
            try {
                date = format.parse(EditProfile.dateOFBirth);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

Post a Comment for "Android Simpledateformat Fails To Parse Datetime (works Fine On Sun 1.6 Jre)"