Date handling in Perl

Problem

You want to convert epoch into readable date and time.

Maybe you have a log file, which is pumping out lines prefixed with the epoch?



Solution

We use the perl function localtime to convert epoch into a date and time.

At the example tab is the code to convert that epoch, into a recognizable date and time.

localtime, can also return an array – take a look at the reference tag for more info.



Example


We quite simply supply the epoch to localtime and print it.


$ perl -e 'print localtime(1145980815)."n";'
Wed Apr 26 00:00:15 2006



Reference

[tags]Perl Date handling, Perl Coding School[/tags]



Leave a Reply

Your email address will not be published. Required fields are marked *