Perl本地时间错误

Her*_*son 1 perl time localtime mktime

我在2009年2月28 得到了纪元时间,然后加上它在一周内的秒数.但后来我得到3月4 而不是3月7 .为什么?

以下是代码:

#!/usr/bin/perl
use POSIX;

my $hours_per_day    =   24;
my $hours_per_week   =  168;
my $seconds_per_hour = 3600;
my $seconds_per_week = ($hours_per_week * $seconds_per_hour);

#begin at my first week
$epoch_seconds = POSIX::mktime(0,0,12,28,2,109);

for(my $cline = 1; $cline <= 250; $cline++) {
    ($sec,$min,$hour,$mday,$month,
     $year,$wday,$yday,$isdst) = localtime($epoch_seconds);

    $year += 1900;
    print STDOUT "$cline <=> $year/$month/$mday\n";

    $epoch_seconds += $seconds_per_week;
}
Run Code Online (Sandbox Code Playgroud)

sha*_*rey 5

您将于2009年3月28日开始,一周后将于2009年4月4日开始.

use POSIX;

my $hours_per_day=24;
my $hours_per_week=168;
my $seconds_per_hour=3600;
my $seconds_per_week=($hours_per_week*$seconds_per_hour);

#begin at my first week
my $epoch_seconds=POSIX::mktime(0,0,12,28,2,109);

for(my $cline=1; $cline<=250; $cline++) {
    my ($sec,$min,$hour,$mday,$month,
     $year,$wday,$yday,$isdst) =localtime($epoch_seconds);

    print strftime( "%A, %B %e, %Y\t", localtime($epoch_seconds) );
    $year+=1900;
    print STDOUT "$cline <=> $year/$month/$mday\n";

    $epoch_seconds+=$seconds_per_week;
}
Run Code Online (Sandbox Code Playgroud)

PS:你真的应该strftime用来格式化你的日期.查看perldoc POSIX并搜索/ strftime /.