php打印出自己想要的日期:
案例:下面是打印出以2017年01月01日为开始,360为周期的的星期一,星期三,,星期六的日期
header(‘Content-type:text/html;charset=utf-8‘);
date_default_timezone_set(‘PRC‘);
$week=array(‘日‘,‘一‘,‘二‘,‘三‘,‘四‘,‘五‘,‘六‘);
function get_next_date($start_day, $weeks) {
$today_week = intval(date(‘w‘, $start_day));
$hour_now = intval(date(‘H‘, $start_day));
$target_week = $today_week;
if (in_array($today_week, $weeks) && $hour_now < 19) {
return strtotime(date("Y-m-d 23:59:59", $start_day));
}
while ($target_week>=0 && $target_week<=7) {
$target_week ++;
if($target_week==7){
$target_week=0;
}
if (in_array($target_week, $weeks)) {
break;
}
}
$delta = $target_week > $today_week? $target_week-$today_week : 7 + $target_week - $today_week;
return strtotime(date("Y-m-d 23:59:59", strtotime("+$delta day", $start_day)));
}
function loop_n_days_date($day, $weeks) {
global $week;
while(round(($day-strtotime(‘2017-01-01‘))/3600/24) <= 360) {
$day = get_next_date($day, $weeks);
$w=date(‘w‘,$day);
$arr[]=date(‘Y-m-d‘, $day)."星期".$week[$w];
}
return $arr;
}
$arr=loop_n_days_date(strtotime(‘2017-01-01‘), [1,3,6]);