Perl 自动投入工作周
现在,我每周都在收集数据,并手动记录每周和每月的数据。例如:本周今天的工作周为6月23日至6月29日。这个月是2014年6月 我想收集年初至今的数据,并根据日期自动输入周和月 例如: 转介请求日期周月 2014年1月3日0:00 2014年12月30日至2014年1月5日Perl 自动投入工作周,perl,Perl,现在,我每周都在收集数据,并手动记录每周和每月的数据。例如:本周今天的工作周为6月23日至6月29日。这个月是2014年6月 我想收集年初至今的数据,并根据日期自动输入周和月 例如: 转介请求日期周月 2014年1月3日0:00 2014年12月30日至2014年1月5日 2014年1月3日11:10 12月30日至2014年1月5日2014年1月 2013年12月31日0:00 12月30日至2014年1月5日2013年12月 2014年6月18日0:00 2014年6月16日至22日2014
2014年1月3日11:10 12月30日至2014年1月5日2014年1月
2013年12月31日0:00 12月30日至2014年1月5日2013年12月
2014年6月18日0:00 2014年6月16日至22日2014年6月
2014年6月20日9:51 2014年6月16日至22日2014年6月
2014年4月28日16:34 2014年4月28日至2014年5月4日
2014年5月1日15:22 2014年4月28日至5月4日2014年5月 工作周从每周一开始,周日结束 它可以自动完成吗??文件有数千行…给您:
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
use DateTime;
use DateTime::Format::Strptime;
my @datetimes = (
'1/3/2014 0:00',
'1/3/2014 11:10',
'12/31/2013 0:00',
'6/18/2014 0:00',
'6/20/2014 9:51',
'4/28/2014 16:34',
'5/1/2014 15:22',
);
for my $datetime_str (@datetimes) {
my $strp = 'DateTime::Format::Strptime'->new( pattern => '%m/%d/%Y %H:%M' );
my $dt = $strp->parse_datetime($datetime_str);
my $month_year_strp = 'DateTime::Format::Strptime'->new( pattern => '%B %Y' );
my $month_year = $month_year_strp->format_datetime($dt);
my $desired_dow = 1; # Monday
$dt->subtract(days => ($dt->day_of_week - $desired_dow) % 7);
my $month_day_strp = 'DateTime::Format::Strptime'->new( pattern => '%B %d' );
my $monday = $month_day_strp->format_datetime($dt);
$dt->add(days => 6);
my $sunday = $month_day_strp->format_datetime($dt);
say "$datetime_str, $monday thru $sunday, $month_year";
}
下次帮助别人(如果这是你想要的——我不确定我是否明白你的问题)。:-)我在评论中使用了@scragar发布的链接。这可能有用: