0

I'm trying to parse a date but I only get an ParseException. I'm working with the Apache DateUtils.

The code with the date that I'm tryting to parse is:

        Locale.setDefault(Locale.ENGLISH);
        System.out.println(Locale.getDefault());
        String[] list = {"EEE, d MMM yyyy HH:mm:ss Z"};
        try {
            DateUtils.parseDateStrictly("Mon, 20 Sep 2013 07:38:22 +0000",
                    list);          
        } catch (ParseException ex) {
            System.out.println(ex);          
        }

One of the things that I did, it was to change my Locale, since my default Locale is es_ES, but it doesn't work anyway.

Why doesn't it work?

rene
  • 41,474
  • 78
  • 114
  • 152
Guille
  • 2,248
  • 3
  • 24
  • 42

2 Answers2

2

Because you're using a strict parser; and September 20, 2013 was a Friday not a Monday. From the api, the parser parses strictly - it does not allow for dates such as "February 942, 1996".

Date d = DateUtils.parseDateStrictly(
      "Fri, 20 Sep 2013 07:38:22 +0000",
      "EEE, d MMM yyyy HH:mm:ss Z");
System.out.println(d);
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Ohhh!!, thank you!!, I got that date from a streaming of twitter, I don't know why it was wrong. – Guille Nov 13 '13 at 08:14
0

Try,

String[] parsePattern = {"EEE, dd MMM yyyy HH:mm:ss Z"};
try {
    Date parsedDate = DateUtils.parseDateStrictly("Fri, 20 Sep 2013 07:38:22 +0000", parsePattern);
    System.out.println(" >>>>>>>>>>>>>>>>>>>>>>>> parsedDate : " + parsedDate);
} catch (ParseException ex) {
    System.out.println(ex);          
}
Parkash Kumar
  • 4,710
  • 3
  • 23
  • 39