获取时间戳 和时间转换

获取时间戳字符串,直接获取为Long类型

 fun getTime(): String {
        return System.currentTimeMillis().toString()
    }

转换你想要的格式

   fun getTime(time: String): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm")
        return sdf.format(Date(time.toLong()))
    }

猜你喜欢

转载自blog.csdn.net/qq_28643195/article/details/107333435