Linux / UNIX: Convert Epoch Seconds To the Current Time
Article Number: 52 | Rating: 2/5 from 1 votes | Last Updated: Fri, May 25, 2018 12:56 PM
How do I convert Epoch seconds to the current time under UNIX or Linux operating systems?
Unix time, or POSIX time, is a system for describing points in time, defined as the number of seconds elapsed since midnight proleptic Coordinated Universal Time (UTC) of January 1, 1970, not counting leap seconds.
Print Current UNIX Time
Type the following command to display the seconds since the epoch:
date +%s |
Sample outputs:
1268727836
Convert Epoch To Current Time
Type the command:
date -d @Epoch date -d @1268727836 date -d "1970-01-01 1268727836 sec GMT" |
Sample outputs:
Tue Mar 16 13:53:56 IST 2010
Please note that @ feature only works with latest version of date (GNU coreutils v5.3.0+). To convert number of seconds back to a more readable form, use a command like this:
date -d @1268727836 +"%d-%m-%Y %T %z" |
Sample outputs:
16-03-2010 13:53:56 +0530

AWK Example
echo 1268727836 | awk '{print strftime("%c",$1)}' |
Perl Example
perl -e "print scalar(localtime(1268727836))" |