英文:
Android Unparseable date exception when try to parse date format
问题
我尝试使用以下代码解析此日期 "Wed Jul 12 2023 23:58:20 GMT+0000 (Coordinated Universal Time)"
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
}
但我得到以下错误
无法解析的日期: "Wed Jul 12 2023 23:58:20 GMT+0000 (Coordinated Universal Time)"
英文:
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)"
答案1
得分: 0
这只会发生在本地化更改时。
在我的情况下,该函数在英语环境下运行正常,但当应用切换到阿拉伯语时,我遇到了问题,
我将 Locale.getDefault() 更改为 Locale.ENGLISH,问题得以解决。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论