在OS / X上将UTC转换为纪元时间

时间:2018-04-13 17:50:39

标签: date

如何将我从卷曲输出(UTC)获得的以下时间戳转换为OS / X上的纪元时间

2018-02-26T04:46:20Z

我尝试过:

$ date -j -f "%a %b %d %T %Z %Y" "2018-02-26T04:45:57Z"
Failed conversion of ``2018-02-26T04:45:57Z'' using format ``%a %b %d %T %Z %Y''
date: illegal time format

1 个答案:

答案 0 :(得分:1)

由于您使用的是UTC (ISO-8601)时间戳,因此您需要对其进行相应格式化:

$ date -jf '%Y-%m-%dT%H:%M:%SZ' '2018-02-26T04:45:57Z' +%s
1519645557
 -j      Do not try to set the date.  This allows you to use the -f flag
         in addition to the + option to convert one date format to
         another.

 -f      Use input_fmt as the format string to parse the new_date provided
         rather than using the default [[[mm]dd]HH]MM[[cc]yy][.ss] format.
         Parsing is done using strptime(3).

BSD General Commands | Date