当前日期和年份显示正确,但显示不正确 时间应该显示正确 代码在kotlin中。有人可以帮我解决问题吗?
object DateTimeHelper {
private fun formatDate(date: String): Date? {
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
sdf.timeZone = TimeZone.getTimeZone("GMT")
var dateIn: Date?
dateIn = try {
sdf.parse(date)
} catch (e: Exception) {
Timber.e(e)
null
}
return dateIn
}
fun getDate(date: String): String {
val sdf = SimpleDateFormat(" MMM dd, yyyy")
val tz = TimeZone.getDefault()
sdf.timeZone = tz
return sdf.format(formatDate(date))
}
fun getTime(date: String): String {
val sdf = SimpleDateFormat("hh:mm aaa")
val tz = TimeZone.getDefault()
sdf.timeZone = tz
return sdf.format(formatDate(date))
}
}