HP实现计算一年多少个星期,返回一个星期的开始时间和结束时间(可选返回时间戳或日期)
2018-07-20 来源:open-open
function getWeekStartAndEnd ($year,$week=1) { header("Content-type:text/html;charset=utf-8"); date_default_timezone_set("Asia/Shanghai"); $year = (int)$year; $week = (int)$week; //按给定的年份计算本年周总数 $date = new DateTime; $date->setISODate($year, 53); $weeks = max($date->format("W"),52); //如果给定的周数大于周总数或小于等于0 if($week>$weeks || $week<=0){ return false; } //如果周数小于10 if($week<10){ $week = '0'.$week; } //当周起止时间戳 $timestamp['start'] = strtotime($year.'W'.$week); $timestamp['end'] = strtotime('+1 week -1 day',$timestamp['start']); //当周起止日期 $timeymd['start'] = date("Y-m-d",$timestamp['start']); $timeymd['end'] = date("Y-m-d",$timestamp['end']); //返回起始时间戳 return $timestamp; //返回日期形式 //return $timeymd; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
最新资讯
热门推荐