此示例采用基准日期并添加7½小时,1天7½小时,2天7½小时等等.
use Date::Manip; use DateTime; use DateTime::Format::DateManip; Date::Manip::Date_Init("TZ=America/New_York","Language=English"); my $otime = DateTime->new( year => 2013,month => 3,day => 4,hour => 0,minute => 0,second => 0,time_zone => 'America/New_York',); my $t1 = UnixDate($otime,"%i:%M %p on %A,%B %e,%Y "); print "original $t1\n"; for (my $i = 0; $i <= 20; $i++) { my $dtw = $otime->clone(); $dtw->add( minutes => (15) * 30,days => ($i),); $t1 = UnixDate($dtw,%Y "); print "$i days $t1\n"; }
当添加6天7½小时时,结果包含额外的小时.
original 12:00 AM on Monday,March 04,2013 0 days 07:30 AM on Monday,2013 1 days 07:30 AM on Tuesday,March 05,2013 2 days 07:30 AM on Wednesday,March 06,2013 3 days 07:30 AM on Thursday,March 07,2013 4 days 07:30 AM on Friday,March 08,2013 5 days 07:30 AM on Saturday,March 09,2013 6 days 08:30 AM on Sunday,March 10,2013 # why 8:30 and not 7:30? 7 days 07:30 AM on Monday,March 11,2013 8 days 07:30 AM on Tuesday,March 12,2013 9 days 07:30 AM on Wednesday,March 13,2013 10 days 07:30 AM on Thursday,March 14,2013 11 days 07:30 AM on Friday,March 15,2013 12 days 07:30 AM on Saturday,March 16,2013 13 days 07:30 AM on Sunday,March 17,2013 14 days 07:30 AM on Monday,March 18,2013 15 days 07:30 AM on Tuesday,March 19,2013 16 days 07:30 AM on Wednesday,March 20,2013 17 days 07:30 AM on Thursday,March 21,2013 18 days 07:30 AM on Friday,March 22,2013 19 days 07:30 AM on Saturday,March 23,2013 20 days 07:30 AM on Sunday,March 24,2013