"Unparseable date" when using "SimpleDateFormat" API to parse a date String into Date object
Issue
When using SimpleDateFormat
API to parse a date String into Date object, the error "java.text.ParseException: Unparseable date" happens.
The code used to parse the date String looks like below:
import java.text.SimpleDateFormat;
import java.util.Date;
... ...
String strDate = "Mon Mar 05 11:41:26 SGT 2018";
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");
Date date = sdf.parse(strDate);
The error looks like below:
11:24:29,178 INFO [stdout] (http-/10.10 10.10:8080-308) Failed to parse the date string: Mon Mar 05 11:41:26 SGT 2018
11:24:29,178 INFO [stdout] (http-/10.10 10.10:8080-308) Unparseable date: "Mon Mar 05 11:41:26 SGT 2018 "
11:24:29,178 ERROR [stderr] (http-/10.10 10.10:8080-308) java.text.ParseException: Unparseable date: "Mon Mar 05 11:41:26 SGT 2018 "
11:24:29,178 ERROR [stderr] (http-/10.10 10.10:8080-308) at java.text.DateFormat.parse(DateFormat.java:366)
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- Windows
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.