I am currently working on a project about schedules. Given a start time and an end time, I need to list the dates within this time period and determine the day of the week at the same time. After research, I have come up with the following method, which I would like to share with you for the convenience of friends in need.
First post the renderings of this demand:
The following is the specific code snippet:
/* *参数分别是开始时间戳,结束时间戳 */ 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.phpernote.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; }