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
Related posts:
How to Provide Sudo Access to User in Linux
How to Remove Sticky Bit in Linux
How to Save Terminal History in Linux
How to Configure DNS Nameserver in Ubuntu
How to Password Protect Folders in Linux
How to Find Users Currently Logged in Linux
How to Install Swift in Ubuntu
How to Run Shell Script on Another Server

Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.