获取某个周在本年的开始日期和结束日期
生活随笔
收集整理的這篇文章主要介紹了
获取某个周在本年的开始日期和结束日期
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳入 年份 和 本年的多少周,計算改周在本年的開始日期和結束日期
/** @Purpose : 根據所給年份和該年的第幾周,得出該周在本年的開始日期和結束日期* @time : 2017/11/03 */ 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); // 參見 http://php.net/manual/zh/datetime.setisodate.php// 一年周的最大值為 52$weeks = max($date->format("W"),52); // $date->format("W") 將日期格式化為 周,//如果給定的周數大于周總數或小于等于0if($week>$weeks || $week<=0){return false;}//如果周數小于10if($week<10){$week = '0'.$week;}//當周起止時間戳$timestamp['start'] = strtotime($year.'W'.$week); // strtotime('2009W32');Get timestamp of 32nd week in 2009. 參見:http://cn2.php.net/manual/zh/function.strtotime.php $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;}$week_time = getWeekStartAndEnd(2017,10);var_dump($week_time);//array (size=2)// 'start' => string '2017-03-06' (length=10)// 'end' => string '2017-03-12' (length=10)參考自:http://www.thinkphp.cn/topic/4491.html
?
轉載于:https://www.cnblogs.com/chrdai/p/7779422.html
總結
以上是生活随笔為你收集整理的获取某个周在本年的开始日期和结束日期的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一个HelloWorld网站
- 下一篇: 错误:子进程 已安装 pre-remov