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 can't understand why this few lines

    Date submissionT;
    SimpleDateFormat tempDate = new SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy");

    public time_print(String time) {
        try {
          submissionT=tempDate.parse(time);
        }
        catch (Exception e) {     
          System.out.println(e.toString() + ", " + time);
        }

    }

Cause exceptions and print out

    java.text.ParseException: Unparseable date: "Tue Mar 31 06:09:00 CEST 2009", Tue Mar 31 06:09:00 CEST 2009

... while the "unparsable" time is compliant with the format string i've passed to SimpleDateFormat().. Any Idea?

See Question&Answers more detail:os

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

1 Answer

It is a Locale issue. Use:

sdf = SimpleDateFormat("EEE MMM d HH:mm:ss z 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

548k questions

547k answers

4 comments

86.3k users

...