![](/img/trans.png)
[英]how to change T Z Format 2022-12-08T06:07:34.780Z (yyyy-MM-dd'T'HH:mm:ss.SSSZ) come to server but Display DD/MM/YYYY
[英]How to parse date "2022-07-18T08:24:18Z" in android
我已經嘗試過這些格式,但沒有奏效。
也試過“ZonedDateTime”,但在 Android O 下不可用。
If your minSDK is 25 or lower you have to use Java 8+ API desugaring support to be able to use the java.time package from Java 8.
啟用后,您可以簡單地使用例如
OffsetDateTime.parse("2022-07-18T08:24:18Z")
ZonedDateTime.parse("2022-07-18T08:24:18Z")
(您可以找到許多有關這些日期格式差異的資源)。
你可以這樣做
fun parseDate(
inputDateString: String?,
inputDateFormat: SimpleDateFormat,
outputDateFormat: SimpleDateFormat
): String? {
var date: Date? = null
var outputDateString: String? = null
try {
date = inputDateFormat.parse(inputDateString)
outputDateString = outputDateFormat.format(date)
} catch (e: ParseException) {
e.printStackTrace()
}
return outputDateString
}
我希望你能從這里得到你的答案
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.