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)"

2
  • @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 Commented Jul 16, 2023 at 1:29
  • 1
    Never use SimpleDateFormat or DateTimeFormatter without a Locale. Also, I recommend you switch from the error-prone legacy date-time API to the modern date-time API. Commented Jul 22, 2023 at 9:57

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.