0

I'm having problems with parsing date in format like this "Dec 21 2017 12:30:45 AM ALMT".

SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy hh:mm:ss a z");
sdf.parse("Dec 21 2017 12:30:45 AM ALMT");

Using the SimpleDateFormat getting me stuck with java.text.ParseException: Unparseable date: "Dec 21 2017 12:30:45 AM ALMT"

Where am I getting wrong? Checked pattern more than once with Java documentation, it looks as recommended.

kozmo
  • 4,024
  • 3
  • 30
  • 48
shx
  • 1,068
  • 1
  • 14
  • 30
  • 1
    Your code works on my computer. A locale issue? – Ole V.V. Feb 02 '18 at 10:10
  • What is ALMT??? – Maurice Perry Feb 02 '18 at 10:18
  • 2
    The `SimpleDateFormat` class is not only long outdated, it is also notoriously troublesome. It doesn’t answer your question, but I recommend you move on to [`java.time`, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Feb 02 '18 at 10:19
  • 1
    @MauricePerry ALMT is [Alma-Ata Time](https://www.timeanddate.com/time/zones/almt). But you are right, those three and four letter abbreviations are not standardized and therefore give rise to confusion, misconception and errors. – Ole V.V. Feb 02 '18 at 10:20
  • 2
    It is a `Locale` issue. You could give it a try with `Locale.ROOT` as one answer of the duplicate explains. Or maybe use the correct locale anyway. And after that, move on to `java.time` ... – Seelenvirtuose Feb 02 '18 at 10:21

0 Answers0