Unix Epoch conversion
Convert a Unix timestamp into human-readable format:
date -date='@1501768813'
date -r 1501768813
Convert the other way
Current date/time as Unix timestamp: date +%s
A specific date/time (assumes current timezone):
date -d '2017-08-13 07:18:42' +%s
date -j -f '%Y-%m-%d %H:%M:%S' '2017-08-13 07:18:42' +%s
A specific date/time with timezone (not sure if these are correct -- UTC+11 in this example):
date -d '2017-08-13 07:18:42+11' +%s
date -j -f '%Y-%m-%d %H:%M:%S' -v +11H '2017-08-13 07:18:42' +%s
Note that the BSD manual for date
(1) has an error, at least on MacOS:
Finally the command: date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s" can be used to parse the output from date and express it in Epoch time.
[mjl@milo:~]
[08:12]$ date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s"
Failed conversion of ``Fri 4 Aug 2017 08:13:55 AEST'' using format ``%a %b %d %T %Z %Y''
date: illegal time format
usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
[mjl@milo:~]
[08:13] 1 $