PHP如何擷取一段時間內的日期列表

來源:互聯網
上載者:User

  最近在做一個關於議程表的項目,給出一個開始時間和一個結束時間,需要列出這個時間段內的日期列表並同時判斷是周幾。經過研究,得出如下方法,和大家共用,方便有需要的朋友。

  先貼一下此次需求的效果圖:

  下面是具體的程式碼片段:

  /*

  *參數分別是開始時間戳,結束時間戳記

  */

  function timeList($beginTimeStamp,$endTimeStamp){

  if(!is_numeric($beginTimeStamp)!is_numeric($endTimeStamp)($endTimeStamp<=$beginTimeStamp)) return "";

  $tmp=array();

  for($i=$beginTimeStamp;$i<=$endTimeStamp;$i+=(24*3600)){

  $tmp["timeStampList"][]=$i;

  $tmp["dayList"][]=date("Y年m月d日",$i);

  $tmp["dayWeek"][]=getWeek($i);

  }

  return $tmp;

  }

  function getWeek($timestamp){

  $timestamp=date("w",$timestamp);

  $str="";//http://www.Alixixi.com/php-function/969.html

  switch($timestamp){

  case "0":

  $str.="周日";

  break;

  case "1":

  $str.="周一";

  break;

  case "2":

  $str.="周二";

  break;

  case "3":

  $str.="周三";

  break;

  case "4":

  $str.="周四";

  break;

  case "5":

  $str.="周五";

  break;

  case "6":

  $str.="周六";

  break;

  }

  return $str;

  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.