Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I try to convert String to Date.

Here is my code:

    SimpleDateFormat format =  new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
    Date date = format.parse("Sun Apr 08 16:37:00 CEST 2012");

I get exception:

04-08 13:51:36.536: W/System.err(8005): java.text.ParseException: Unparseable date: "Sun Apr 08 16:37:00 CEST 2012".

Format seems to be ok. Am I missing something?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
293 views
Welcome To Ask or Share your Answers For Others

1 Answer

Either the code you posted is not your actual code, or you have a locale issue. It works fine on Sun Oracle Java 1.6 with a US locale.

Change your code to:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...