0

I try to parse this date "Wed Jul 12 2023 23:58:20 GMT+0000 (Coordinated Universal Time)" using this code

  val sdf = SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss ", Locale.getDefault())
    val time = try {
        val mDate = sdf.parse(input)
        mDate!!.time
    } catch (e: ParseException) {
        -1
    }

But I get this error

Unparseable date: "Wed Jul 12 2023 23:58:20 GMT+0000 (Coordinated Universal Time)"

Amin
  • 463
  • 2
  • 11
  • 29
  • @Unmitigated You are right this only happens if the localization changed. on my case the function works fine in English but when the app turns to Arabic here I faced the issue , I Changed Locale.getDefault() to Locale.ENGLISH and the problem solved – Amin Jul 16 '23 at 01:29
  • 1
    [Never use `SimpleDateFormat` or `DateTimeFormatter` without a Locale](https://stackoverflow.com/a/65544056/10819573). Also, I recommend you switch from the error-prone legacy date-time API to the modern date-time API. – Arvind Kumar Avinash Jul 22 '23 at 09:57

1 Answers1

0

This only happens if the localization changed. on my case the function works fine in English but when the app turns to Arabic here I faced the issue ,

I Changed Locale.getDefault() to Locale.ENGLISH and the problem solved

Amin
  • 463
  • 2
  • 11
  • 29