开发者

How do I get an array of days of the month with Perl Date::Manip?

I'm using Date::Manip for a variety of things, and want to开发者_StackOverflow create an array of days of the month. I think I need:

@date = &ParseRecur("2010:4:0:0:0:0:0"); 

but, it doesn't do it. I've read & reread the man page but can't get the syntax.

@date = &ParseRecur("2010:4:0:1:0:0:0"); 
@date = &ParseRecur("2010:4:0:1*:0:0:0"); 

don't work either!


You could build the list with your own loop, instead of using ParseRecur.

$month = 4;
for ($day = 1; $day <= 31; $day++) {
    my $date = UnixDate( "$month/$day/2010", "%m-%d-%Y" );
    push( @list, $date ) if (defined $date);
}


From the man pages: "There are a small handful of English strings which can be parsed in place of a numerical recur description." Check out the examples in the man page.

So, if you want an array of days of a month - say for June in 2010 you would do:

@dates = ParseRecur("every day in June 2010");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜