convert epoch to date in linux

How to Convert Epoch to Date in Linux

Epoch time is a time format which displays the number of seconds since midnight of Jan 1, 1970. But sometimes you may need to convert epoch to date in Linux.


How to Convert Epoch to Date in Linux

Here is the command to display present datetime in epoch format.

$ date +%s
1634801456

Here’s is the command to convert epoch to date in Linux.

$ date -d @1634801456
Thu Oct 21 07:30:56 UTC 2021

You can also specify format string at the end of date command, to customize the output.

$ date -d @1634801456 +"%d-%m-%Y %T %z"
21-10-2021 07:30:56 +0000

You can also use awk command to get the same output.

$ echo 1634801456 | awk '{print strftime("%c",$1)}'
Thu Oct 21 07:30:56 2021

In this short article, we have seen how to convert epoch to date in Linux. You can use the above commands in shell scripts, applications and even websites, as per your requirement.

Also read:

How to View Linux Log Files
How to Convert to UTF-8 Files in Linux
How to Set or Change Hostname in CentOS/RHEL
How to Convert Webpage o PDF in Linux
How to Find & Remove Duplicate Files in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *