Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 906
David Young Avatar asked Sep 28 '10 23:09

David Young


People also ask

How do I manually convert a date to a timestamp in Unix?

To easily convert UNIX timestamp to date in the . csv file, do the following: 1. =R2/86400000+DATE(1970,1,1), press Enter key.

How do you convert date to epoch time in bash?

Use the build-in date command and instruct it to output the number of seconds since 1970-01-01 00:00:00 UTC. You can do this by passing a format string as parameter to the date command. The format string for UNIX epoch time is '%s'. To convert a specific date and time into UNIX epoch time, use the -d parameter.


1 Answers

date +%s 

This works fine for me on OS X Lion.

like image 84
JRiggles Avatar answered Oct 13 '22 05:10

JRiggles