Date formatting exception unparseable date

I am trying to format dates entered by my application user using SimpleDateFormat but I always get an error:

 01/28/2014java.text.ParseException: Unparseable date: "01/28/2014"

The code I am using to format the date is as follows:

    Date rDate, dDate;
    String Date1 = request.getParameter("Date1");       
    String Date2 = request.getParameter("Date2");

    //Here the date get display for example as 01/29/2014 (i.e. MM/DD/YYYY)
    System.out.println("Date1::   "+ Date1);
    System.out.println("Date2::   "+ Date2);

    SimpleDateFormat parseRDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleDateFormat parseDDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    try {
        //#########Crashes in the next two lines#########...
        rDate = (Date)parseRDate.parse(Date1);
        dDate = (Date)parseDDate.parse(Date2);

    } catch (ParseException e) {
        e.printStackTrace();
    }

Can someone please help me by telling me what I am doing wrong here?

Thanks for your time

Jon Skeet
people
quotationmark

As you say, Date1 is of the form MM/dd/yyyy... but you're trying to parse it with a format of yyyy-MM-dd HH:mm:ss.

The pattern you parse to the SimpleDateFormat constructor has to match the format of the data itself. (What did you think you were specifying in the constructor?)

Note that the code you've provided isn't doing and formatting at all - just parsing.

You should also work out which time zone you're interested in, and which Locale. Personally I think it's clearer to specify both of those explicitly - even if you want the system default ones.

(If you're doing any significant amount of date/time work, you should also consider using Joda Time, which is a much more pleasant date/time API. I'd also consider more useful exception handling, and following Java naming conventions...)

people

See more on this question at Stackoverflow