【发布时间】:2021-07-10 20:26:01
【问题描述】:
所以我正在创建一个函数来根据我设置的时间格式查看日期格式是否有效。函数如下所示:
private fun isDateInvalid(time: String, timeFormat: String): Boolean {
return try {
val dateFormat = SimpleDateFormat(timeFormat, Locale.getDefault())
dateFormat.isLenient = false
dateFormat.parse(time)
false
} catch (e: ParseException){
Log.d("Tag",e.toString())
true
}
}
所以在这个函数中,我将time 的参数传递为"07:45",将timeFormat 传递为HH:MM。我做错了什么?
【问题讨论】:
-
MM代表月份,mm代表分钟。 -
另外,
isLenient()只是一个get方法。您应该使用setLenient()或lenient作为属性。
标签: android android-studio kotlin error-handling