"Unparseable date" when using "SimpleDateFormat" API to parse a date String into Date object

Updated 2018-06-18T07:05:41+00:00

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 content preview. For full access to the Red Hat Knowledgebase, please log in.

Not a subscriber? Learn more about the benefits of Red Hat Subscriptions.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.