HP實現計算一年多少個星期,返回一個星期的開始時間和結束時間(可選返回時間戳或日期)
- 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;
- }
复制代码
|
可選, 一個星期, 幾個
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31