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

Another simple question yet I'm getting stumped...

Trying to convert an epoch time like 1370376667000 to a datetime format, such as 2013-06-04 16:00:00. Trying conventional parsers and even one designed for Epoch, but coming up with issues....

my $epoch = "1370376667000"; my $formatter = DateTime::Format::Epoch::Unix->new(); my $newtime = $formatter->parse_datetime("$epoch");
Doing this comes up with a bad format, such as 45395-07-05 01:16:40, it should be 2013-06-04 16:11:07. Any thoughts? Please note, I don't care about using the DateTime::Format::Epoch::Unix package, but I would like to know how this can be done in just DateTime or basically the most simple method

Replies are listed 'Best First'.
Re: Epoch Converter
by BrowserUk (Patriarch) on Jun 04, 2013 at 21:09 UTC
    Any thoughts?

    Your 'epoch time' is in milliseconds but epochs are in seconds. divide it by 1000 (or just insert a decimal point; or truncate it):

    print scalar localtime 1370376667000;; Use of uninitialized value in print at (eval 9) line 1, <STDIN> line 1 +. [Invalid argument] print scalar localtime 1370376667.000;; Tue Jun 4 21:11:07 2013

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Epoch Converter
by NetWallah (Canon) on Jun 04, 2013 at 23:33 UTC