PHP gets a few weeks a year and a weekly start date and end date, a few weeks start date
Recently, a project was taken, with one requirement being PHP to get a few weeks a year and a weekly start date and contact date. Find some information on the Internet is not appropriate, so I made a copy, the following two ways to achieve PHP to obtain a few weeks a year and a weekly start date and end date
Code One:
<?phpheader ("Content-type:text/html;charset=utf-8");d ate_default_timezone_set ("Asia/shanghai"); $year = (int) $ _get[' year '; $week = (int) $_get[' Week '); $weeks = Date ("W", mktime (0, 0, 0, $year)); Echo $year. ' A total of years '. $weeks. ' Week
' If ($week > $weeks | | $week <= 0) {$week = 1;} if ($week <) {$week = ' 0 '. $week;} $timestamp [' start '] = Strtotime ($year. ' W '. $week); $timestamp [' end '] = Strtotime (' +1 week-1 Day ', $timestamp [' Start ']); Echo $year. ' Year of the first '. $week. ' Week start timestamp: '. $timestamp [' Start ']. '
'; Echo $year. ' Year of the first '. $week. ' Week end timestamp: '. $timestamp [' End ']. '
'; Echo $year. ' Year of the first '. $week. ' Week start date: '. Date ("y-m-d", $timestamp [' Start ']). '
'; Echo $year. ' Year of the first '. $week. ' Week End Date: '. Date ("y-m-d", $timestamp [' End ']); >
Code two:
<?phpheader ("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 = Dat E (' D-m-y ', strtotime (' This week Sunday ', $custom _date)); $week _array[0] = $week _start; $week _array[1] = $week _end; return $week _array;} Echo '
Weeks in 2013
' . Getisoweeksinyear, $weekday = Weekday (Strtotime (' D-m-y ', strtotime (' 5-8-2013 '))), Echo '
10-8-2013 '; Echo '
Start: '. $weekday [0];echo '
End: '. $weekday [1];? >
All of the above, I hope to learn PHP for you to get a few weeks a year and a weekly start date and end date, helpful.
http://www.bkjia.com/PHPjc/1044256.html www.bkjia.com true http://www.bkjia.com/PHPjc/1044256.html techarticle PHP Gets a few weeks in a year and a weekly start date and end date, a few weeks from the start date of a recent project, and one of the requirements is to get a year with PHP for a few weeks and a weekly start date ...