简体   繁体   中英

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 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!

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");

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM