How to convert DATE to UNIX TIMESTAMP in shell script on MacOS

后端 未结 6 688
滥情空心
滥情空心 2021-01-30 02:53

On Linux you can convert a date like \"2010-10-02\" to a unix timestamp in shell script by

date -d \"2010-10-02\" \"+%s\"

Since Mac OS does not

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 03:24

    date -j -f "%Y-%m-%d %H:%M:%S" "2020-04-07 00:00:00" "+%s"

    It will print the dynamic seconds when without %H:%M:%S and 00:00:00.

提交回复
热议问题