ProTips: dealing with unix timestamp from the shell

Oct 3, 2015  

Get the current UNIX timestamp

Eg: Tue Sep 22 23:34:33 UTC 2015

$ date +%s
1442964873

Get the UNIX timestamp of a specific date.

OSX use this pattern [[[mm]dd]HH]MM[[cc]yy][.ss]]

$ date -ju 092223342015.33 +%s
1442964873
  • -j : do not set the date
  • -u : input date is UTC

Linux use this pattern mm/dd/ccyy HH:MM:ss

$ date -d "09/22/2015 23:34:33" +%s
1442964873

Convert Unix timestamp to Human readable format

OSX for local timezone

$ date -r 1442964873
Tue Sep 22 16:34:33 PDT 2015

OSX in UTC

$ date -ur 1442964873
Tue Sep 22 23:34:33 UTC 2015

Linux in UTC

$ date -d @1442964873
Tue Sep 22 23:34:33 UTC 2015