Chrometobia Chrometobia - 7 months ago 16
Java Question

Parsing date string

I am trying to parse a formatted date back to a Date object but I keep encountering exceptions, here is my code:

DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy ", Locale.ENGLISH);
date = dateFormat.parse(dateString);


When I try a date like
Apr 17, 2016
it gives me an
ParserException
to say
Unparseable date: "Apr 17, 2016" (at offset 12)

Answer

Try as follows

DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);

Date date = dateFormat.parse(dateString);
Comments