kotlin --- 时间戳与字符串互相转换

直接贴代码,清晰易懂。喜欢点个赞

class Timestamp {
    /**
     * Timestamp to String
     * @param Timestamp
     * @return String
     */
     fun transToString(time:Long):String{
        return SimpleDateFormat("YY-MM-DD-hh-mm-ss").format(time)
    }

    /**
     * String to Timestamp
     * @param String
     * @return Timestamp
     */

    fun transToTimeStamp(date:String):Long{
        return SimpleDateFormat("YY-MM-DD-hh-mm-ss").parse(date, ParsePosition(0)).time
    }
}
posted @ 2019-10-22 15:45  Gyyyang  阅读(...)  评论(... 编辑 收藏