我需要將String格式中的日期轉換為Thu。2021 年 9 月 23 日,來自 Api。Api 發送了許多日期,我希望所有日期都被轉換。(帶擴展檔案)怎么做?
uj5u.com熱心網友回復:
使用SimpleDateFormat,
val date = SimpleDateFormat("dd/MM/yy").parse("31/11/2021");
這將產生您想要的輸出。
即,星期四 12 月 31 日 00:00:00 IST 1998
uj5u.com熱心網友回復:
您可以將此代碼片段用作 kotlin 擴展。
fun Date.convertDate(dateString:String) : String{
val inFormat = SimpleDateFormat("dd/MM/yy")
var date: Date? = null
try {
date = inFormat.parse(dateString)
} catch (e: ParseException) {
e.printStackTrace()
}
val outFormat = SimpleDateFormat("dd MM, YYYY")
return outFormat.format(date)
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/327936.html
上一篇:按T??SQL中的連續日期分組
