我正在尝试使用 SimpleDateFormat
解析日期字符串,该字符串从不停止也不给出任何异常。请看下面的代码,
fun getDate(dateStr: String) {
try {
/** DEBUG dateStr = '2006-04-16T04:00:00Z' **/
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH)
val mDate = formatter.parse(dateStr) // this never ends while debugging
} catch (e: Exception){
Logger.e("Error $e") // this never gets called either
}
}
可能的问题是什么?
注意:我正在使用,
Android Studio: 3.4.1, Kotlin version: 1.3.31, Min SDK: 23, Target SDK: 28, Compile SDK: 28
最佳答案
使用下面的函数
fun getDate(dateStr: String) {
try {
/** DEBUG dateStr = '2006-04-16T04:00:00Z' **/
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH)
val mDate = formatter.parse(dateStr) // this never ends while debugging
Log.e("mDate", mDate.toString())
} catch (e: Exception){
Log.e("mDate",e.toString()) // this never gets called either
}
}
关于android - Kotlin - SimpleDateFormat 解析需要无限时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678746/