Perl : Convert time from Epoch to local time


This little Perl one-liner can get handy when you need to translate “time in seconds since the Epoch” (for example in logs) to local time :
% perl -e 'print scalar(localtime(1202484725)), "\n";'
Fri Feb 8 16:32:05 2008

This was pretty useful today when browsing through Nagios event logs, where times are given in seconds from the Epoch.

By the way, the Epoch is defined as 00:00 UTC on January, 1st, 1970.

3 thoughts on “Perl : Convert time from Epoch to local time”

  1. On Windows you have to swap the quotes

    perl -e “print scalar(localtime(1202484725)), ‘\n’;”

Comments are closed.