object DateUtil {
private const val dateFormat = "yyyy-MM-dd HH:mm:ss"
private val threadLocal: ThreadLocal<DateFormat> = ThreadLocal<DateFormat>()
@SuppressLint("SimpleDateFormat")
private fun getDateFormat(): DateFormat {
var df: DateFormat? = threadLocal.get()
if (df == null) {
df = SimpleDateFormat(dateFormat)
threadLocal.set(df)
}
return df
}
@SuppressLint("SimpleDateFormat")
fun getTestDate(test: String): String? {
val short="yyyy/MM/dd hh:mm:ss"
val currentTime = getDateFormat().parse(test)
println(currentTime)
val formatter = SimpleDateFormat(short).format(currentTime)
return formatter.format(currentTime)
}
}
日期转化工具类DateUtil
最新推荐文章于 2024-06-14 16:58:26 发布