gpt4 book ai didi

不同格式的 Perl 日期差异

转载 作者:行者123 更新时间:2023-12-02 03:34:48 27 4
gpt4 key购买 nike

我的 perl 代码中有如下两个日期-

my $asof_date;
chomp($asof_date = `date +'%m/%d/%Y'`);

另一个来自 sql 表的日期是 -$date = $syb_row[3];

here $date is in the form of "Dec 20 2013 12:00AM"

现在我的帮助是计算成熟度 - 其中成熟度是两个日期之间的天数差异(即上述情况下的 $asof_date 和 $date)除以 365。

是的,我安装了有限的模块,因为没有安装 parsedate。

提前致谢。

最佳答案

use strict;
use warnings;

use DateTime;
use DateTime::Format::Strptime;

...;

my $db_parse = DateTime::Format::Strptime->new(
pattern => '%B %d %Y %R%p',
locale => 'en_US',
time_zone => 'America/New York', ### Olson TZ name
);

my $asof_date = DateTime->now(time_zone => 'local');
my $db_date = $db_parse->parse_datetime($syb_row[3]);

my $maturity = $asof_date->delta_days($db_date)->days / 365;

关于不同格式的 Perl 日期差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24310081/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com