-1

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?

jmj
  • 237,923
  • 42
  • 401
  • 438
Amil
  • 609
  • 1
  • 5
  • 12
  • 1
    How is not working? Works just fine for me... – MadProgrammer Mar 22 '15 at 23:49
  • 1
    what is your default `Locale` – jmj Mar 22 '15 at 23:50
  • 1
    @MadProgrammer Yeah, but it's probably english. (response to comment on Jigar's answer) – Sotirios Delimanolis Mar 22 '15 at 23:50
  • @JigarJoshi You should undelete your answer and add information that locale need to support English names of months like `Locale.US` or `Locale.UK`. – Pshemo Mar 22 '15 at 23:52
  • I voted to close your question as duplicate based on assumption that over 90% of problems with parsing `MMM` involves locale which doesn't support English names of months. If that wasn't the problem feel free to inform me and I will reopen your question. – Pshemo Mar 22 '15 at 23:57
  • Using `DateFormat df = new SimpleDateFormat("MMM d HH:mm:ss");` and inputing `Dec 6 04:13:01`, outputs `Sun Dec 06 04:13:01 EST 1970` for me. What are your expectations? – MadProgrammer Mar 23 '15 at 00:01
  • @SotiriosDelimanolis I was more curious about why you though it would help then thinking it was a mistake ;) – MadProgrammer Mar 23 '15 at 00:01
  • I see the **year is missing** in that input string. – Basil Bourque May 17 '17 at 07:04

1 Answers1

4

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));
jmj
  • 237,923
  • 42
  • 401
  • 438