Get current time in seconds since the Epoch on Linux, Bash


I need something simple like date, but in seconds since 1970 instead of the current date, hours, minutes, and seconds.

date doesn't seem to offer that option. Is there an easy way?

3/5/2018 8:59:09 PM

Accepted Answer

This should work:

date +%s
7/7/2009 2:25:00 PM

Just to add.

Get the seconds since epoch(Jan 1 1970) for any given date(e.g Oct 21 1973).

date -d "Oct 21 1973" +%s

Convert the number of seconds back to date

date --date @120024000

The command date is pretty versatile. Another cool thing you can do with date(shamelessly copied from date --help). Show the local time for 9AM next Friday on the west coast of the US

date --date='TZ="America/Los_Angeles" 09:00 next Fri'

Better yet, take some time to read the man page

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow