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

后端 未结 6 785
滥情空心
滥情空心 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:27

    man date on OSX has this example

    date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
    

    Which I think does what you want.

    You can use this for a specific date

    date -j -f "%a %b %d %T %Z %Y" "Tue Sep 28 19:35:15 EDT 2010" "+%s"
    

    Or use whatever format you want.

提交回复
热议问题