kiluch has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I am new in Perl and I would like to convert timestamp taken from PostgreSQL database to Date in format YYYY/mm/dd HH:MM:ss.
The problem is that the timestamp has 13 digit instead of 10?
I tried:
my $epoch = 1260439520772; my $date = strftime '%Y/%m/%d %H:%M:%S', localtime $epoch;
But the result is odd.
If anyone has any ideas how to convert 13 digit timestamp to date, please help me?
Thanks in advance.

Replies are listed 'Best First'.
Re: How to convert 13 digits Epoch to Date
by almut (Canon) on Jan 12, 2010 at 15:08 UTC

    Presumably, the last three digits are msecs. Try simply cutting them off (divide by 1000):

    use POSIX; my $epoch = 1260439520772; my $date = strftime '%Y/%m/%d %H:%M:%S', localtime $epoch/1000; print "date=$date\n"; __END__ date=2009/12/10 11:05:20

      Thanks very much.

      It seems to be working fine.

      Really appreciate.