php计算当前是一年或一月中第几周的函数。

php计算当前是一年或一月中第几周的函数。

 1     //[PHP]计算当前是教学第几周的函数 
 2     //function current_week ($date_of_firstday)  
 3     //功能:返回但前是第几周 
 4     //参数:$date_of_firstday 默认值为 2006-9-1 
 5     //参数格式:字符串 2006-9-1 不要出现01、02、03、04 
 6     //如果2006年9月1日星期四开学,便于计算,将开学那周的周一的日期计为开学日期。 
 7      
 8     function current_week ($date_of_firstday='2006-8-28'){ 
 9         //开学第一天的时间戳 
10         $year = substr($date_of_firstday,0,4); 
11         $month = substr($date_of_firstday,5,1); 
12         $day = substr($date_of_firstday,7,2); 
13         $time_chuo_of_first_day = mktime(0,0,0,$month,$day,$year); 
14         //今天的时间戳 
15         $month = date('n'); //获取月 n 
16         $day = date('d');   //获取日 d 
17         $year = date('Y');  //获取年 Y 
18         $time_chuo_of_current_day = mktime(0,0,0,$month,$day,$year); 
19         $cha = ($time_chuo_of_current_day-$time_chuo_of_first_day)/60/60/24; 
20         $zhou = (int)(($cha)/7 +1); 
21         return $zhou; 
22     } 
原文地址:https://www.cnblogs.com/sunzhenkun/p/7910756.html