Obtain the weekly list and weekly start time in a year-PHP source code

Source: Internet
Author: User
I searched for the weekly list and weekly start time for half a day on the Internet within a year. I did not find the list and wrote one myself.
Don't talk to me about the optimal algorithm. if you have several more CPU clock cycles, you won't be able to die.

public static function getWeeks($format="second",$year=null){if($year == null){$year=date('Y');}$second_of_day = 24*3600;$year_start = $year ."-01-01 00:00:00"; $year_end = $year ."-12-31 23:59:59"; $startday = strtotime($year_start); $day_of_week = date('N', $startday);$first_week_start=$startday;$first_week_end = $startday+(7-$day_of_week)*$second_of_day+$second_of_day-1;$week_array[0]=array($first_week_start,$first_week_end);$endday = strtotime($year_end); $day_of_week = date('N', $endday);$last_week_start=$endday-$day_of_week*$second_of_day+1;$last_week_end = $endday;$last_week=array($last_week_start,$last_week_end);$during = $last_week_start - $first_week_end;$during_total_week = intval($during/(7*$second_of_day));for($i=0;$i<$during_total_week;$i++){$week_array[$i+1]=array($first_week_end+(7*$i*$second_of_day)+1,$first_week_end+(($i+1)*$second_of_day*7));}$week_array[$during_total_week+1]=$last_week;if($format !="second"){foreach($week_array as $i => $week){$week_array_of_date_format[$i]=array(date($format,$week[0]),date($format,$week[1]));}return $week_array_of_date_format;}return $week_array;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.