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 +%sSample 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
WARNING! Note that the date and awk command syntax may not work on all versions of UNIX. Please refer to your local man page.AWK Example
echo 1268727836 | awk '{print strftime("%c",$1)}'
Perl Example
perl -e "print scalar(localtime(1268727836))"See also:
- Refer to your local date, and awk command man or info pages.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 4 comments… read them below or add one }
don’t you need a final ‘ in your awk example above? ie:
echo 1268727836 | awk ‘{print strftime(“%c”,$1)}’
Thanks for the heads up!
You can also run a while loop to read stuff with epoch time in it, example:
while read b epoch therest ; do echo $b `date -d@$epoch` $therest; done
Hi,
Can you please tel me how to convert seconds into current date and time. shell script?
date -d @ // getting error msg
I am working on HP_UX