每周二重复一次 每周的每个星期六重复一次。基于事件
示例:
5 recurrence means , the event will repeat 5times like
tuesday , saturday, tuesday, saturday, tuesday
我的代码是
$ron
是用户选择的工作日1=monday
,2=tuesday
等。
$ron="1,5,3";
$ronS=explode(',', $ron);
foreach($ronS as $ronS) {
$res[]= $ronS;
}
$s ="09-05-2014 00:00:00";
$ii=0;
$m= date("M",strtotime($s));
$curday= 7-date("N",strtotime($s));
foreach($res as $key=>$val)
{
$week = array('0'=>"Sunday","1"=>"Monday","2"=>"Tuesday","3"=>"Wednesday","4"=>"Thursday","5"=>"Friday","6"=>"Saturday");
$day[] = $week[$val]."-";
$ncount= $res[$key];
if($ii==0)
{
$nc=$ncount+$curday;
$cday= date('Y-m-d H:i:s',strtotime('+'.$nc.' day',strtotime($s)));
// echo $st=date('Y-m-d H:i:s', strtotime('Next '.$day));
$ii++;
}
else
{
$nc=$ncount+$curday;
$cday= date('Y-m-d H:i:s',strtotime('+'.$nc.' day',strtotime($s)));
$ii++;
}
$datetime = new DateTime("$cday");
if ( $datetime->format("w") >= 0 )
{
echo "\n $cday is ".$datetime->format("l")."\n";
}
}
此代码的输出为:
2014-05-12 00:00:00 is Monday
2014-05-16 00:00:00 is Friday
2014-05-14 00:00:00 is Wednesday
如果用户输入为$ron="1,2,3"
且出现次数为5,则出现次数表示天数重复的次数。
示例o / p:
$ron="1,3";
$occurances=5
$s ="09-05-2014 00:00:00";
o / p将是
2014-05-12 00:00:00 is Monday
2014-05-14 00:00:00 is Wednesday
2014-05-19 00:00:00 is Monday
2014-05-21 00:00:00 is Wednesday
2014-05-26 00:00:00 is Monday
抱歉我的英语不好。任何想法的朋友。