I want to parse a date that includes AM/PM format from String to Timestamp.
Although when I try to parse this date: Dec 31 2017 12:00AM
I get a
Exception in thread "main" java.text.ParseException: Unparseable date: "Dec 31 2017 12:00AM"
at java.text.DateFormat.parse(Unknown Source)
at test.DatteTest.main(DatteTest.java:16)
My code:
String endDate = "Dec 31 2017 12:00AM";
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy hh:mmaa");
Date parsedDate = dateFormat.parse(endDate);
Timestamp timestamp = new Timestamp(parsedDate.getTime());
System.out.println(endDate);
System.out.println(timestamp);
Am I doing something wrong in the simpledateformat? "MMM dd yyyy hh:mmaa"?