3.3.3. Discussion
The localtime and gmtime
functions return strange year and month values; the year has 1900
subtracted from it, and 0 is the month value for January. Be sure to
correct the base values for year and month, as this example does:
($seconds, $minutes, $hours, $day_of_month, $month, $year,
$wday, $yday, $isdst) = localtime($time);
printf("Dateline: %02d:%02d:%02d-%04d/%02d/%02d\n",
$hours, $minutes, $seconds, $year+1900, $month+1,
$day_of_month);
We could have used the Time::localtime module to avoid the temporary
variables:
use Time::localtime;
$tm = localtime($time);
printf("Dateline: %02d:%02d:%02d-%04d/%02d/%02d\n",
$tm->hour, $tm->min, $tm->sec, $tm->year+1900,
$tm->mon+1, $tm->mday);