MrBadGuy
MrBadGuy

Reputation: 33

JodaTime - IllegalArgumentException: Invalid format: "Mon, 29 Oct 2018 15:17:19 +0000"

I'm receiving a crash from a single device when it tries to parse a date

class DateTimeUtils {
  public static DateTime toDateTime(String value) {
     return DateTime.parse(value, DateTimeFormat.forPattern("EEE, d MMM yyyy HH:mm:ss Z"));
  }
}

Stack trace

Caused by java.lang.IllegalArgumentException: Invalid format: "Mon, 29 Oct 2018 15:17:19 +0000"
   at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
   at org.joda.time.DateTime.parse(DateTime.java:160)
   at com.example.app.DateTimeUtils.toDateTime(DateTimeUtils.java:58)

Any ideas?

Upvotes: 0

Views: 1087

Answers (1)

MrBadGuy
MrBadGuy

Reputation: 33

The problem was solved by setting the locale same as locale of the date to be parsed (in this case US). The device on which crash was happening had different one.

DateTime.parse(value, DateTimeFormat.forPattern("EEE, d MMM yyyy HH:mm:ss Z").withLocale(Locale.US));

Upvotes: 1

Related Questions