Can't parse using SimpleDateFormat [duplicate]

2019-03-06 19:20发布

问题:

This question already has an answer here:

  • Java - Unparseable date 2 answers

I'm trying to parse "Dec 6 04:13:01" with "MMM d HH:mm:ss", but it is not working! I spent a lot of time but cant figure it out.

Any ideas why it fails?

回答1:

You are probably trying to parse it with JAPANESE locale (guessing it from your profile + your web page), specify any english locale for example: Locale.US

String dateString = "Dec 6 04:13:01";
DateFormat df = new SimpleDateFormat("MMM d HH:mm:ss", Locale.US);
System.out.println(df.parse(dateString));