How to convert Unix timestamp to date time format in Linux?

When it comes to the measurement of time, the “epoch” serves as the reference point from which time is measured.

In Unix and Unix-like operating systems, the date is internally represented as the number of seconds since Jan 1 1970 at 00:00:00 UTC which is known as Unix epoch time.

Sometimes you need to convert Unix epoch time or Unix timestamp to date time format and vice versa. For this conversion, we can use the date command in Linux.

How to display Unix epoch time

As discussed earlier the epoch or Unix timestamps is the number of seconds that have passed since 1 Jan 1970, at 00:00:00 UTC.

To show the number of seconds from the epoch to now, use the %s format control –

date +%s

This will display the number of seconds, you can see this in the image below.

Convert Unix timestamp to date in Linux

You can convert the Unix timestamp or second elapsed since the epoch to a human-readable date format by using the options -ud with the date command.

date -ud @1627278292

This will display the given output.

Convert date to Unix timestamp in Linux

If you want to convert a date to a Unix epoch timestamp then use the given command in your terminal.

date -d '07/20/2021 06:05:43' +"%s"

This will display the number of seconds elapsed since the Unix epoch.

Please note that you have to enter the date in MM/DD/YYYY format.

For more information, you can check the man page of the date command in your terminal by using –

man date


In this article, you have learned what is Unix epoch time, conversion of epoch time to human readable date formats, and vice versa.

Now if you have a query then write us in the comments below.

Leave a Comment