用php获取本周,上周,本月,上月,本季度日期的代码

 1 echo date("Ymd",strtotime("now")), "\n";
 2 echo date("Ymd",strtotime("-1 week Monday")), "\n";
 3 echo date("Ymd",strtotime("-1 week Sunday")), "\n";
 4 echo date("Ymd",strtotime("+0 week Monday")), "\n";
 5 echo date("Ymd",strtotime("+0 week Sunday")), "\n";
 6  
 7  
 8 //date('n') 第几个月
 9 //date("w") 本周周几
10 //date("t") 本月天数
11  
12 echo '<br>上周:<br>';
13 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"))),"\n";
14 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"))),"\n";
15 echo '<br>本周:<br>';
16 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))),"\n";
17 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"))),"\n";
18  
19 echo '<br>上月:<br>';
20 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))),"\n";
21 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))),"\n";
22 echo '<br>本月:<br>';
23 echo date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))),"\n";
24 echo date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))),"\n";
25  
26 $getMonthDays = date("t",mktime(0, 0 , 0,date('n')+(date('n')-1)%3,1,date("Y")));//本季度未最后一月天数
27 echo '<br>本季度:<br>';
28 echo date('Y-m-d H:i:s', mktime(0, 0, 0,date('n')-(date('n')-1)%3,1,date('Y'))),"\n";
29 echo date('Y-m-d H:i:s', mktime(23,59,59,date('n')+(date('n')-1)%3,$getMonthDays,date('Y'))),"\n";

转自:http://www.cnblogs.com/whlives/p/5795458.html

posted @ 2017-04-12 09:14  YGCool  阅读(2943)  评论(0编辑  收藏  举报