我需要将unix时间戳转换为日期对象.
我试过这个:
java.util.Date time = new java.util.Date(timeStamp);
Run Code Online (Sandbox Code Playgroud)
时间戳值是: 1280512800
日期应该是"2010/07/30 - 22:30:00"(因为我通过PHP得到它),但我得到了Thu Jan 15 23:11:56 IRST 1970.
应该怎么做?
代码A可以将long值转换为日期值,就像2018.01.10
我希望获得日期+时间值,例如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)
}
Run Code Online (Sandbox Code Playgroud)