PHP獲取一年有幾周以及每周開始日期和結(jié)束日期
更新時間:2015年08月06日 11:11:59 投稿:mrr
這篇文章主要介紹php計算一年有多少周,獲取每周開始日期和結(jié)束日期,有需要的朋友可以參考一下
最近接了一個項目,其中有一需求是用php獲取一年有幾周以及每周開始日期和接觸日期。在網(wǎng)上找些資料沒有合適的,于是自己做了一份,下面通過兩種方式實現(xiàn)PHP獲取一年有幾周以及每周開始日期和結(jié)束日期
代碼一:
<?php header("Content-type:text/html;charset=utf-8"); date_default_timezone_set("Asia/Shanghai"); $year = (int)$_GET['year']; $week = (int)$_GET['week']; $weeks = date("W", mktime(0, 0, 0, 12, 28, $year)); echo $year . '年一共有' . $weeks . '周<br />'; if ($week > $weeks || $week <= 0) { $week = 1; } if ($week < 10) { $week = '0' . $week; } $timestamp['start'] = strtotime($year . 'W' . $week); $timestamp['end'] = strtotime('+1 week -1 day', $timestamp['start']); echo $year . '年第' . $week . '周開始時間戳:' . $timestamp['start'] . '<br />'; echo $year . '年第' . $week . '周結(jié)束時間戳:' . $timestamp['end'] . '<br />'; echo $year . '年第' . $week . '周開始日期:' . date("Y-m-d", $timestamp['start']) . '<br />'; echo $year . '年第' . $week . '周結(jié)束日期:' . date("Y-m-d", $timestamp['end']); ?>
代碼二:
<?php header("Content-type:text/html;charset=utf-8"); function getIsoWeeksInYear($year) { $date = new DateTime; $date->setISODate($year, 53); return ($date->format("W") === "53" ? 53 : 52); } function weekday($custom_date) { $week_start = date('d-m-Y', strtotime('this week monday', $custom_date)); $week_end = date('d-m-Y', strtotime('this week sunday', $custom_date)); $week_array[0] = $week_start; $week_array[1] = $week_end; return $week_array; } echo '<br> Weeks in 2013<br>' . getIsoWeeksInYear(2013); $weekday = weekday(strtotime(date('d-m-Y', strtotime('5-8-2013')))); echo '<br> 10-8-2013'; echo '<br>Start: ' . $weekday[0]; echo '<br>End: ' . $weekday[1]; ?>
以上本文的全部內(nèi)容,希望對大家學習PHP獲取一年有幾周以及每周開始日期和結(jié)束日期,有所幫助。
您可能感興趣的文章:
相關(guān)文章
用 Composer構(gòu)建自己的 PHP 框架之基礎(chǔ)準備
這篇文章主要介紹了用 Composer構(gòu)建自己的 PHP 框架的基礎(chǔ)準備工作,其實就是各種基礎(chǔ)知識,想自己搭建php框架的童鞋可要看仔細了2014-10-10

thinkPHP3.2.3結(jié)合Laypage實現(xiàn)的分頁功能示例
這篇文章主要介紹了thinkPHP3.2.3結(jié)合Laypage實現(xiàn)的分頁功能,結(jié)合實例形式分析了thinkPHP3.2.3結(jié)合Laypage實現(xiàn)分頁的model控制器與view視圖相關(guān)操作技巧,需要的朋友可以參考下
2018-05-05 
下拉列表多級聯(lián)動dropDownList示例代碼
本文為大家詳細介紹下下拉列表多級聯(lián)動 dropDownList具體的實現(xiàn)代碼,感興趣的朋友可以參考下哈,至于一些細節(jié)部分后續(xù)再補
2013-06-06 
解決Linux下php-fpm進程過多導致內(nèi)存耗盡問題
這篇文章主要介紹了解決Linux下php-fpm進程過多導致內(nèi)存耗盡問題,需要的朋友可以參考下
2017-12-12