Android parse String to Date - unknown pattern character 'X'

前端 未结 13 1392
耶瑟儿~
耶瑟儿~ 2021-01-31 07:32

I have Service fetch date string from web and then I want to pare it to Date object. But somehow application crashes. This is my string that I\'m parsi

13条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 08:15

    No one has mentioned about this error occurring on pre-nougat devices so I thought to share my answer and maybe it is helpful for those who reached this thread because of it.

    This answer rightly mentions that "X" is supported only for Nougat+ devices. I still see that documentation suggests to use "yyyy-MM-dd'T'HH:mm:ss.SSSXXX" and not sure why they don't make this point explicit.

    For me, yyyy-MM-dd'T'HH:mm:ssXXX was working fine until I tried to test it on 6.0 device and it started crashing which led me to research on this topic. Replacing it with yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ has resolved the issue and works on all 5.0+ devices.

提交回复
热议问题