views:

133

answers:

2

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 have the equivalent -d for date. How do you go about converting a date to a unix timestamp in a shell script.

+2  A: 

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.

Lou Franco
+2  A: 

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

Vlad Lazarenko