Java: Date from unix timestamp

后端 未结 10 1587
北荒
北荒 2020-11-22 04:10

I need to convert a unix timestamp to a date object.
I tried this:

java.util.Date time = new java.util.Date(timeStamp);

Timestamp value

10条回答
  •  梦毁少年i
    2020-11-22 04:42

    For kotlin

    fun unixToDate(timeStamp: Long) : String? {
        val time = java.util.Date(timeStamp as Long * 1000)
        val sdf = SimpleDateFormat("yyyy-MM-dd")
        return sdf.format(time)
    
    }
    

提交回复
热议问题