相关的问题是“Datetime到Unix时间戳”,但这个问题更一般。
我需要Unix时间戳来解决最后一个问题。我的兴趣是Python、Ruby和Haskell,但也欢迎其他方法。
生成Unix时间戳最简单的方法是什么?
相关的问题是“Datetime到Unix时间戳”,但这个问题更一般。
我需要Unix时间戳来解决最后一个问题。我的兴趣是Python、Ruby和Haskell,但也欢迎其他方法。
生成Unix时间戳最简单的方法是什么?
当前回答
curl icanhazepoch.com
基本上它是unix时间戳即服务(UTaaS)
其他回答
在锈:
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let now = SystemTime::now();
println!("{}", now.duration_since(UNIX_EPOCH).unwrap().as_secs())
}
$ date +%s.%N
where (GNU Coreutils 8.24日期手册)
+%s, seconds since 1970-01-01 00:00:00 UTC +%N,纳秒(000000000..999999999)
示例现在输出1454000043.704350695。 我注意到BSD手册的日期没有包括关于标志+%s的精确解释。
呜:
$ nawk 'BEGIN{print srand()}'
甚至可以在旧版本的Solaris和其他UNIX系统上工作,在这些系统中“date +%s””没有实现 不能在Linux和其他posix工具已经被GNU版本(nawk -> gawk等)取代的发行版上工作。 很不直观,但肯定很有趣:-)
使用NodeJS,只需打开一个终端并键入:node -e "console.log(new Date().getTime())"或node -e "console.log(Date.now())"
在Haskell
import Data.Time.Clock.POSIX
main :: IO ()
main = print . floor =<< getPOSIXTime
在去
import "time"
t := time.Unix()
in C
time(); // in time.h POSIX
// for Windows time.h
#define UNIXTIME(result) time_t localtime; time(&localtime); struct tm* utctime = gmtime(&localtime); result = mktime(utctime);
在斯威夫特
NSDate().timeIntervalSince1970 // or Date().timeIntervalSince1970