-1

To clarify my question the original problem is that I was trying to :

I don't know the problem with this code:

    SimpleDateFormat fromFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss a");
    String date = "Sep 13, 2016 6:16:46 PM";
    Date parse = fromFormat.parse(date);

I got this error:

Exception in thread "main" java.text.ParseException: Unparseable date: "Sep 13, 2016 6:16:46 PM"
Pablo Souza
  • 863
  • 2
  • 11
  • 25

3 Answers3

0

in my IDE,I haven't got your error,but met with this

    Date parse = toFormat.parse(formated); 

error found:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Unhandled exception type ParseException

Maybe our java versions is different. for Class SimpleDateFormat, I got reference to JAVA API according to my JAVA version. It is the the lack of parameter that resulted in the error I faced.

as this

0

Your SimpleDateFormat instances use different patterns, so the second instance can not parse a date formatted by the first one

larsgrefer
  • 2,735
  • 19
  • 36
0

Thanks all!

I found the error:

My default locale is incompatible with the input date. So I need to set the Locale:

SimpleDateFormat fromFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss a", Locale.US);
    String date = "Sep 13, 2016 6:16:46 PM";
    Date parse = fromFormat.parse(date);
Pablo Souza
  • 863
  • 2
  • 11
  • 25