【发布时间】:2018-03-29 08:36:38
【问题描述】:
代码 A 可以将 long 值转换为日期值,就像 2018.01.10
希望得到Date + Time的值,比如2018.01.10 23:11,Kotlin怎么办?
我希望将当前时间转换为长值,我该如何使用 Kotlin?
谢谢!
代码 A
fun Long.toDateString(dateFormat: Int = DateFormat.MEDIUM): String {
val df = DateFormat.getDateInstance(dateFormat, Locale.getDefault())
return df.format(this)
}
【问题讨论】:
-
使用
SimpleDateFormatdeveloper.android.com/reference/java/text/SimpleDateFormat.html -
谢谢!你能用 Kotlin 展示一些代码吗?
-
如果我有时间我可以,但是从 JAva 转换代码很容易