标签:wear gic pbc dmp omd wss ytd crm gdm3
1.制定周计划,
2.从周一开始;
3.本月第一个周一之前的日期算到上一个月:
-------------
1 /***$date 是时间戳***/ 2 function getWeek($date) 3 { 4 $result = array(); 5 $week = array(); 6 //天: 7 $d = date(‘d‘, $date); 8 // echo ‘天:‘. $d . ‘</br>‘; 9 10 //月: 11 $m = date(‘m‘, $date); 12 // echo ‘月:‘ .$m. ‘</br>‘; 13 14 //年: 15 $Y = date(‘Y‘, $date); 16 // echo ‘年:‘ .$Y. ‘</br>‘; 17 18 //月的天数: 19 $t = date(‘t‘, $date); 20 // echo ‘月有‘ .$t. ‘天</br>‘; 21 22 //月的开始时间戳: 23 $startMonth = mktime(0,0,0,$m,1,$Y); 24 // echo ‘月的开始时间戳:‘ .$startMonth. ‘</br>‘; 25 26 //月的结束时间戳: 27 $endMonth = mktime(23,59,59,$m,$t,$Y); 28 // echo ‘月的结束时间戳:‘ .$endMonth. ‘</br>‘; 29 30 $result[‘startMonth‘] = $startMonth; 31 $result[‘endMonth‘] = $endMonth; 32 33 for($i=1; $i<=$t; $i++) 34 { 35 //判断是否是周一: 36 if (date(‘N‘, mktime(0,0,0,$m,$i,$Y)) == 1) 37 { 38 $mondayStr = date(‘Y-m-d‘, mktime(0,0,0,$m,$i,$Y)); 39 $startWeek = mktime(0,0,0,$m,$i,$Y); 40 $endWeek = $startWeek+7*24*60*60-1; 41 $week[$mondayStr][‘startWeek‘] = $startWeek; 42 $week[$mondayStr][‘endWeek‘] = $endWeek; 43 } 44 } 45 $result[‘week‘] = $week; 46 // var_dump($week); 47 48 //上一月 和 下一月: 49 $before_Y = $Y; 50 $before_m = $m - 1; 51 $after_Y = $Y; 52 $after_m = $m + 1; 53 54 if($m == 1) 55 { 56 $before_Y = $Y -1; 57 $before_m = 12; 58 } 59 60 if($m == 12) 61 { 62 $after_Y = $Y + 1; 63 $after_m = 1; 64 } 65 66 $beforeMonth = mktime(0,0,0,$before_m,1,$before_Y); 67 $afterMonth = mktime(0,0,0,$after_m,1,$after_Y); 68 69 $result[‘beforeMonth‘] = $beforeMonth; 70 $result[‘afterMonth‘] = $afterMonth; 71 72 return $result; 73 } 74 75 $currDate = strtotime(‘2017-03-04‘); 76 var_dump(getWeek($currDate));
结果:
1 array(5) { 2 ["startMonth"]=> 3 int(1488297600) 4 ["endMonth"]=> 5 int(1490975999) 6 ["week"]=> 7 array(4) { 8 ["2017-03-06"]=> 9 array(2) { 10 ["startWeek"]=> 11 int(1488729600) 12 ["endWeek"]=> 13 int(1489334399) 14 } 15 ["2017-03-13"]=> 16 array(2) { 17 ["startWeek"]=> 18 int(1489334400) 19 ["endWeek"]=> 20 int(1489939199) 21 } 22 ["2017-03-20"]=> 23 array(2) { 24 ["startWeek"]=> 25 int(1489939200) 26 ["endWeek"]=> 27 int(1490543999) 28 } 29 ["2017-03-27"]=> 30 array(2) { 31 ["startWeek"]=> 32 int(1490544000) 33 ["endWeek"]=> 34 int(1491148799) 35 } 36 } 37 ["beforeMonth"]=> 38 int(1485878400) 39 ["afterMonth"]=> 40 int(1490976000) 41 }
startMonth 本月的开始: 转为格式是 2017-03-01 00:00:00 ;
endMonth 本月的结束: 转为格式是 2017-03-31 23:59:59;
第一个周一是: 2017-03-06;
startWeek 周一的开始: 转为格式是 2017-03-06 00:00:00;
endWeek 周日的结束: 转为格式是 2017-03-12 23:59:59
第二个周一是: 2017-03-13
beforeMonth: 前一个月的开始: 转为格式是 2017-02-01 00:00:00
afterMonth : 后一个月的开始: 转为格式是 2017-04-01 00:00:00
-----------------------
3月:
5月:
12月:
2018-01:
标签:wear gic pbc dmp omd wss ytd crm gdm3
原文地址:http://www.cnblogs.com/cbza/p/6410473.html