下面是在主要语言中获取 当前 Unix 时间戳 的方法。大多数返回秒(10 位)或毫秒(13 位)。
- JavaScript —
Math.floor(Date.now() / 1000)(秒),Date.now()(毫秒) - Python —
int(time.time()) - Java —
System.currentTimeMillis() / 1000L - PHP —
time() - Go —
time.Now().Unix() - Ruby —
Time.now.to_i - C# —
DateTimeOffset.UtcNow.ToUnixTimeSeconds() - Swift —
Int(Date().timeIntervalSince1970) - Bash —
date +%s - MySQL —
SELECT UNIX_TIMESTAMP()
注意不要把秒和毫秒弄混。把任意值粘贴到网站顶部的转换器中,即可立即将其显示为可读日期。