一:字符串转字符串——如“2017-12-12 12:12:12”转成“2017年12月12日”
工具类:
fun String.toDate(pattern:String):Date{
return SimpleDateFormat(pattern).parse(this)
}
fun Date.toString(pattern:String):String{
return SimpleDateFormat(pattern).format(this)
}
fun String.toDateFormat(sourcePattern:String,targetPattern:String):String{
try {
return this.toDate(sourcePattern).toString(targetPattern)
}catch (ex:Throwable){
return ""
}
}
调用:
endTime.text = t.endTime.toDateFormat("yyyy-MM-dd","yyyy年MM月dd日")