Bash tips, tricks and code snippets

Date conversion to and from epoch


To get epoch seconds for right now

date +%s

or for a specific date

date -d "Oct 21 1973" +%s

and to convert from epoch to a date format

date --date @120024000

might output something like (depending on locale settings)

Sun Oct 21 05:00:00 CET 1973

Get epoch in millisecs:

echo $(($(date +%s%N)/1000000))