Scala UTC timestamp in seconds since January 1st, 1970

女生的网名这么多〃 提交于 2021-02-04 10:33:47

问题


How do I get the Scala UTC timestamp in seconds since January 1st, 1970?


回答1:


Same way as you would in Java:

val timestamp: Long = System.currentTimeMillis / 1000



回答2:


As of Java 8 it's possible to do so like so:

import java.time.Instant
unixTimestamp : Long = Instant.now.getEpochSecond

Via micha's answer here: https://stackoverflow.com/a/24703573/577199



来源:https://stackoverflow.com/questions/11352037/scala-utc-timestamp-in-seconds-since-january-1st-1970

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!