This article mainly introduces based on PHP to obtain a month of the week information, interested in a friend's reference, I hope to be helpful to everyone.
Specific as follows:
<?php function Getmonthweeks ($date) {$ret =array (); $stimestamp =strtotime ($date); $mdays =date (' t ', $stimestamp); $msdate =date (' y-m-d ', $stimestamp); $medate =date (' y-m-' $mdays, $stimestamp); $etimestamp = Strtotime ($medate); For the first week $zcsy =6-date (' W ', $stimestamp);//The first week of removal of the first day and a few days $zcs 1= $msdate; $zce 1=date (' y-m-d ', strtotime ("+ $zcsy Day", $stimestamp)); $ret [1]= "1th Week". $zcs 1. ' ~ '. $zce 1; To obtain a medium-time week $JZC = 0; The current month is 6 weeks or 5 weeks $jzc 0 = ""; $JZC 6 = ""; for ($i = $stimestamp; $i <= $etimestamp; $i +=86400) {if (date (' W ', $i) = = 0) {$jzc 0++;} if (Date (' W ', $i) = = 6) {$jzc 6++;}} if ($jzc 0==5 && $jzc 6==5) {$jzc = 5;} else{$jzc =4;} date_default_timezone_set (' PRC '); $t = Strtotime (' +1 Monday '. $msdate); $n = 1; for ($n =1; $n < $jzc; $n + +) {$b = Strtotime ("+ $n week-1 Week", $t); $dsdate =date ("y-m-d", Strtotime ("-1 day", $b)) $ded Ate=date ("y-m-d", Strtotime ("5 Day", $b)); $jzcz = $n +1; $ret [$jzcz]= ". $jzcz." Week ". $dsdate. ' ~ '. $dedate; }//For the last week $zcsy =date (' W ', $etimestamp);//Last week is weeks to six 0~6 $zcs 1=date (' y-m-d ', StRtotime ("-$zcsy Day", $etimestamp)); $zce 1= $medate; $jzcz = $jzc +1; $ret [$jzcz]= ". $jzcz." Week ". $zcs 1. ' ~ '. $zce 1; return $ret;} $ret =getmonthweeks (' 2012-12-01 '); for ($i =0; $i <=count ($ret); $i + +) {echo @ $ret [$i]. " <br/> ";}? >
The results of the operation are as follows:
1th Week 2012-12-01~2012-12-01
2nd Week 2012-12-02~2012-12-08
3rd Week 2012-12-09~2012-12-15
4th Week 2012-12-16~2012-12-22
5th Week 2012-12-23~2012-12-29
6th Week 2012-12-30~2012-12-31
Summary : The above is the entire content of this article, I hope to be able to help you learn.
Related recommendations:
PHP implementation Curl upload, download, HTTPS login
A few ways to implement the static page of PHP
PHP implementation of hexadecimal color random generator function method