Perl time Vs Unix date output inconsistency -



Perl time Vs Unix date output inconsistency -

i total beginner in perl , trying first perl script convert time info in epoch-sconds specific format. understand month jan = 0 , year 1900 = 0 in perl other stackoverflow questions. after adjusting them, not seeing identical outputs between unix , perl.

here tried , got.

unix:

date -d @915149280

gives me:

thu dec 31 19:08:00 est 1998

perl:

$time = 915149280; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($time); $year = $year + 1900; $mon = $mon + 1; print "formated time = $mday/$mon/$year $hour:$min:$sec $weekday[$wday]\n";

gives me:

formated time = 1/1/1999 0:8:0 fri

is there error in perl lines? should same output date command? (not formatting part, time)

i not looking fields, year of import me.

i assume you're talking time difference rather format difference, since perl code doesn't effort replicate format.

use localtime instead of gmtime. date command uses local time default. notice says "est", gmtime returns utc, 5 hr difference.

you should consider using module handle date formatting. won't prevent confusion between local time , utc.

perl unix unix-timestamp

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -