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

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


date +%s

This works fine for me on OS X Lion.


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.


date -j -f "%Y-%m-%d" "2010-10-02" "+%s"