自 1970 年 1 月 1 日以来的 Scala UTC 时间戳(以秒为单位)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11352037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 04:19:55 来源:igfitidea点击:
Scala UTC timestamp in seconds since January 1st, 1970
提问by user1491739
How do I get the Scala UTC timestamp in seconds since January 1st, 1970?
如何获得自 1970 年 1 月 1 日以来的 Scala UTC 时间戳(以秒为单位)?
回答by Dan Simon
Same way as you would in Java:
与您在 Java 中的方式相同:
val timestamp: Long = System.currentTimeMillis / 1000
回答by Ceasar Bautista
As of Java 8 it's possible to do so like so:
从 Java 8 开始,可以这样做:
import java.time.Instant
unixTimestamp : Long = Instant.now.getEpochSecond
Via micha's answer here: https://stackoverflow.com/a/24703573/577199
通过 micha 的回答:https://stackoverflow.com/a/24703573/577199

