我有以下时间格式
"2014-06-02T16:23:13+02:00"
我想将它转换为 unix 时间戳(从 1/1/1970 开始)。对于上面的例子,命令应该返回:
1401725705
有 linux 命令吗?
最佳答案
date -d"2014-06-02T16:23:13+02:00" +%s
如果您有较新的 GNU coreutil,应该可以使用。我用最新的 v8.22 测试过。
如果您使用的是较旧的 coreutil 机器,例如 8.4。它不起作用,您可以尝试将 T
替换为空格。在 date -d"2014-06-02 16:23:13+02:00"+% 中使用字符串
"2014-06-02 16:23:13+02:00"
s
这是在 Red Hat Enterprise Linux Server release 6.5 (Santiago)
上用 coreutil 8.4
测试的
$>date -d"2014-06-02 16:23:13+02:00" +%s
1401718993
关于linux - 将时间转换为 unix 时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24019278/