Skip to content

Unparseable date exception in java

These lines of codes

SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yy"); 

     ContentValues values = new ContentValues();
        values.put(COL_EVENT_ID, appointment.mEventId);
        try {
            values.put(COL_START_DATE, String.valueOf(formatter.parse(appointment.mStartDate.toString())));
            values.put(COL_END_DATE, String.valueOf(formatter.parse(appointment.mEndDate.toString())));

        } catch (ParseException e) {
            // TODO Auto-generated catch block

causees this exception

10-15 11:44:38.150: WARN/System.err(3861): java.text.ParseException: Unparseable date: "Mon Jan 10 00:10:00 GMT+02:00 2011"

what is the possible solution ?



Your format is completely wrong. Not only are you using mm (which means minutes) when you probably meant MM, but this:

Mon Jan 10 00:10:00 GMT+02:00 2011

is clearly not in the format


You probably want something like

EEE MMM dd HH:mm:ss z yyyy

EDIT: That works for me in desktop Java:

import java.text.*;

public class Test {

    public static void main(String[] args) throws ParseException {
        String value = "Mon Jan 10 00:10:00 GMT+02:00 2011";
        String pattern = "EEE MMM dd HH:mm:ss z yyyy";
        DateFormat format = new SimpleDateFormat(pattern);

You may want to set the culture of the SimpleDateFormat of course.

1 People found this is helpful