use DateTime ;
my $date = "2010-08-02 09:10:08";
my $dt = DateTime->now(time_zone => 'local')->set_time_zone('floating');
print $dt->subtract_datetime($date);
它不工作;問題是什麼?如何計算Perl中的DateTime差異?
的錯誤信息是:
Can't call method "time_zone" without a package or object reference at
/opt/perl/perl5.12/lib/site_perl/5.12.0/x86_64-linux/DateTime.pm line 1338
定義您的$ data var爲日期時間: my $ date = DateTime-> new(year => 2010,month => 8,day => 2,hour => 9,minute => 10,second => 8); – benzebuth 2010-08-02 15:24:15