in reply to POSIX::mktime() or Time::Local::timelocal()
This prints:use strict; use Time::Local; use POSIX; my ($time,$time2,$sec,$min,$hour,$mday,$mon,$year,$isdst); my ($wday, $yday, $hm); $sec = 59; $min = 59; $hour = 0; $mon = 9; $mday = 28; $year = 2001; $time = timelocal($sec,$min,$hour,$mday,$mon,$year); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+1900, +$hour,$min,$sec); print "Local time: $hm and DST is $isdst\n"; # Skip ahead one hour. $time += 3600; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($tim +e); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+1900, +$hour,$min,$sec); print "Local time: $hm and DST is $isdst\n"; $time2 = timelocal($sec,$min,$hour,$mday,$mon,$year); if ($time == $time2) { print "timelocal conversion correct -- timestamp is $time\n"; } else { print "timelocal conversion error -- $time converted to $time2\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t +ime2); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+19 +00,$hour,$min,$sec); print "(Local time: $hm and DST is $isdst)\n"; } $time2 = POSIX::mktime($sec,$min,$hour,$mday,$mon,$year,0,0,1); if ($time == $time2) { print "mktime conversion correct -- timestamp is $time\n"; } else { print "mktime conversion error -- $time converted to $time2\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($t +ime2); $hm = sprintf("%02d/%02d/%04d %02d:%02d:%02d",$mon+1,$mday,$year+19 +00,$hour,$min,$sec); print "(Local time: $hm and DST is $isdst)\n"; } # -------- end of example -----------
Local time: 10/28/2001 00:59:59 and DST is 1 Local time: 10/28/2001 01:59:59 and DST is 1 timelocal conversion error -- 1004255999 converted to 1004259599 (Local time: 10/28/2001 01:59:59 and DST is 0) mktime conversion correct -- timestamp is 1004255999
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: POSIX::mktime() or Time::Local::timelocal()
by real.aussie (Initiate) on Apr 24, 2012 at 06:40 UTC |