Linux / UNIX: Convert Epoch Seconds To the Current Time

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:

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • ian r Mar 26, 2010 @ 13:56

    don’t you need a final ‘ in your awk example above? ie:
    echo 1268727836 | awk ‘{print strftime(“%c”,$1)}’

  • Allan Sep 28, 2010 @ 4:23

    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

  • anu Nov 1, 2011 @ 17:29


    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

  • iddles Jun 29, 2012 @ 10:21

    How ridiculous that the date command could convert from local time format to epoch time, but not back the other way (except in newer versions). What an oversight. *n*x can boggle the mind at times.

    Even now the @1234567890 syntax isn’t even mentioned in the man page.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @