我如何从json中获取时间,其中我的值如下:
"time": ["1507457400000", "1507458600000"] //Strings
在Javascript中,我可以这样做
new Date(1507457400000) // return Sun Oct 08 2017 12:10:00 GMT+0200
new Date(1507457400000).getHours() // return 12
new Date(1507457400000).getMinutes() // return 10
但是我不知道怎么用kotlin来争取时间。你知道从我拥有的数据中获取时间的最好方法是什么吗?
发布于 2018-07-14 02:27:43
val date = SimpleDateFormat("HH:mm").format(Date((1507457400000 / 1000)))
发布于 2018-07-14 01:27:40
使用以下命令:
val calendar = Calendar.getInstance()
calendar.timeInMillis = 1507457400000
val date = calendar.time
如果在像str
这样的字符串中有毫秒
val calendar = Calendar.getInstance()
calendar.timeInMillis = str.toLong()
val date = calendar.time
对于小时和分钟:
val h = calendar.get(Calendar.HOUR_OF_DAY)
val m = calendar.get(Calendar.MINUTE)
val result = h.toString() + ":" + m.toString()
https://stackoverflow.com/questions/51330064
复制相似问题