php列印日期

來源:互聯網
上載者:User

標籤: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列印日期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.