文件修改时间,unix时间戳,Perl中的时区?

时间:2013-02-05 02:19:00

标签: perl

我想保留今天的登录日志目录。

use POSIX qw(mktime);
use Time::Local;
my $file="20130204.log";
print "$file\t";
open my $fh,'<',$file;
my $modtime = (stat($fh))[9];
print "modtime:$modtime\n";
my $time = timelocal(59,59,23,4,2,2013);
print "Time::Local::time(2013-2-4 23:59:59) => $time\n";
$time = mktime(59,59,59,4,2,2013-1900,0,0);
print "mktime(2013-2-4 23:59:59) => $time\n";

结果:

20130204.log        modtime:1359989999
Time::Local::time(2013-2-4 23:59:59) => 1362409199
mktime(2013-2-4 23:59:59) => 1362538799

dateTue Feb 5 10:57:00 JST 2013

ls -l

-rw-r--r-- 1 root root 945203711 Feb  4 23:59 20130204.log

date -d '2013-02-04 23:59:59' +%s:1359989999

为什么Time :: Local :: time和mktime不给我1359989999?

1 个答案:

答案 0 :(得分:1)

Jan = 0,1900 = 0

$time = timelocal(59,59,23,4,2-1,2013-1900);
$time = mktime(59,59,59,4,2-1,2013-1900,0,0);