user2611714 user2611714 - 11 months ago 38
Java Question

Can't parse date format with SimpleDateFormat

I have a string "Thu Jan 01 01:32:49 EDT 1970" and trying to parse it with java.text.SimpleDateFormat

public class Main {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf_date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
Date d = sdf_date.parse("Thu Jan 01 01:32:49 EDT 1970");

And get the exception:

Exception in thread "main" java.text.ParseException: Unparseable date: "Thu Jan 01 01:32:49 EDT 1970"
at java.text.DateFormat.parse(
at Main.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(

I can't understand, what's wrong?


I think its a Locale issue, because the code worked for me. Try:

new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",Locale.US);