Search code examples
androiddatekotlinparsingcalendar

kotlin : error while parsing a date withe GMT+01:00 as a timezone


I'm parsing a String that has a date format into a variable of type date. When I ran the code in the emulator it worked fine because the time zone was UTC. Once I tried to run it on my phone it didn"t work because the time zone is GMT+01:00 as you can see in the error below

Caused by: java.text.ParseException: Unparseable date: "Mon Feb 01 22:55:22 GMT+01:00 2021"

And here is the code withe the problem

 val cal = Calendar.getInstance()
 val sdf = SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",Locale.ENGLISH)
 cal.time = sdf.parse(reminderdate)

Your help would be appreciated thank you


Solution

  • I suggest you to try this:
    SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);