javadatelocalesimpledateformatdatetime-parsing

Error using SimpleDateFormat


I'm trying to use the SimpleDateFormat class to parse a DateTime out of this string:

05-Jul-2012 11:38:02,442 UTC AM

I tried the following format string:

SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss,SSS z a");

Date temp = dateformatYYYYMMDD.parse(time);

But it generates the error:

Error: Unparseable date: ""

If I use zZ I get : Error: Unparseable date: "05-Jul-2012 11:38:02,442 UTC AM"

Any hints on how to get around this?


Solution

  • That works fine for me when I try to run:

    String time = "05-Jul-2012 11:38:02,442 UTC AM";
    SimpleDateFormat dateformatYYYYMMDD = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss,SSS z a");
    Date temp = dateformatYYYYMMDD.parse(time);
    

    Are you sure time is set to something?