Kotlin JavaScript Date.now()返回types
我想知道为什么Kotlin JavaScript Date
类为getTime
函数返回Double。 根据文档 , getTime
函数应该返回自1970年1月1日00:00:00 UTC以来的毫秒数。
我知道JS没有64位的数字表示,但是由于Kotlin 模拟了Longs,我觉得Date.now()
和Date().getTime()
应该是一个Long返回的值。 至少返回一个Int更合理。
是否有任何理由返回Double而不是整数?
在kotlin中使用Date().time。它将返回long值,您将得到整数
val s= Date().time print(s)
例如
val date = "01-02-2018 07:05:00.999" val fmt = SimpleDateFormat("MM-dd-yyyy HH:mm:ss.S") //parse date based your format var myDate: Date? = null try { myDate = fmt.parse(date) } catch (e: ParseException) { e.printStackTrace() } println(myDate) val timestamp = myDate!!.time //timestamp values in long only not double println(timestamp)