Perl time Vs Unix date output inconsistency
I assume you're talking about the time difference rather than the format difference, since your Perl code doesn't even attempt to replicate that format.
Use localtime
instead of gmtime
. The date
command uses your local time by default. Notice that it says "EST", but gmtime
returns UTC, a 5 hour difference.
You should also consider using a module to handle the date formatting. But that won't prevent confusion between local time and UTC.
Time::Piece has been included with Perl for almost seven years and will make your time and date code far easier.
use Time::Piece;my $then = gmtime(915149280);print $then->strftime('%d-%m-%Y %H:%M:%S %a'); # produces 01-01-1999 00:08:00 Fri
You can make this considerably easier by using strftime
from the POSIX module.
perl -MPOSIX=strftime -le 'print strftime "%a %b %d %T %Y",localtime(915149280)'
Thu Dec 31 16:08:00 1998
The POSIX
module has been a core module since 1994. By using an explicit import list, you avoid loading some 500+ symbols that you don't require.