码迷,mamicode.com
首页 > Web开发 > 详细

php打印日期

时间:2017-04-14 11:46:15      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:str   glob   today   char   rto   loop   header   function   开始   

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

php打印日期

标签:str   glob   today   char   rto   loop   header   function   开始   

原文地址:http://www.cnblogs.com/gaoxuqing/p/6708008.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!