在Perl中建议使用日期算术的方法是什么?
发布时间:2020-12-15 21:52:31 所属栏目:大数据 来源:网络整理
导读:在Perl中建议使用日期算术的方法是什么? 比如我想知道三天前的日期(今天= 2010-10-17和今天 – 3天= 2010-10-13).你会如何在Perl中做到这一点? 解决方法 您可以使用DateTime和DateTime :: Duration http://search.cpan.org/dist/DateTime/lib/DateTime/Dur
在Perl中建议使用日期算术的方法是什么?
比如我想知道三天前的日期(今天= 2010-10-17和今天 – 3天= 2010-10-13).你会如何在Perl中做到这一点? 解决方法
您可以使用DateTime和DateTime :: Duration
http://search.cpan.org/dist/DateTime/lib/DateTime/Duration.pm 或者使用unix时间戳: my $now = time(); my $threeDaysAgo = $now - 3 * 86400; my ($day,$mon,$year) = (localtime($threeDaysAgo))[3,4,5]; printf("Three days ago was %04d-%02d-%02d",$year+1900,$mon+1,$day); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |