Convert Unix timestamp to a readable date in Perl

Quick shell one-liner:

perl -le 'print scalar localtime 1357810480;'
Thu Jan 10 10:34:40 2013

Or, if you happen to have the timestamps in a file, one per line:

perl -lne 'print scalar localtime $_;' <timestamps

A perfect use for Time::Piece (standard in Perl since 5.10).

use 5.010;
use Time::Piece;

my $unix_timestamp = 1e9; # for example;

my $date = localtime($unix_timestamp)->strftime('%F %T'); # adjust format to taste

say $date; # 2001-09-09 02:46:40

Tags:

Perl

Timestamp