Home > Backend Development > PHP Tutorial > php计算当前是一年或一月中第几周的函数

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

WBOY
Release: 2016-06-20 13:03:05
Original
2197 people have browsed it

利用php计算当前是一年或一月中第几周的函数,当然可以自定义第一天的时间,然后计算相对于自定义第一天的时间,当前时间是第几周,在做一些关于学校类的项目时可能会用到,在这里与大家分享了。具体函数代码如下。

/*

[PHP]计算当前时间相对于第一天是第几周的函数
功能:返回但前是第几周
参数:$firstDate,第一天的日期或者第一天的时间戳,默认为今年的第一天
返回值:int
author:www.scutephp.com
*/
function current_week($firstDate=''){
$firstDate=empty($firstDate)?strtotime(date('Y').'-01-01'):(is_numeric($firstDate)?$firstDate:strtotime($firstDate));
//开学第一天的时间戳
list($year,$month,$day)=explode('-',date('Y-n-j',$firstDate));
$time_chuo_of_first_day=mktime(0,0,0,$month,$day,$year);
//今天的时间戳
list($year,$month,$day)=explode('-',date('Y-n-j'));
$time_chuo_of_current_day=mktime(0,0,0,$month,$day,$year);
$zhou=intval(($time_chuo_of_current_day-$time_chuo_of_first_day)/60/60/24/7)+1;
return $zhou;
}
Copy after login

PHP 计算某日是这一年的第几周

echo intval(date('W',strtotime('2012-10-30')));
Copy after login

 


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template