在判断某一天是哪一年的第几周的时候,根据采用的国际标准(忘了叫什么名字了),年首或者年末的那几天有可能不属于今年的第一周或者最后一周。
代码如下:
<?php
echo date("oW",strtotime("20141229"))."\n";
echo date("oW",strtotime('20160101'))."\n";
?>
扩展资料
php计算时间段的天数:
$firstday = date("Y-m-d H:i:s",time());//当前日期
$timestamp=strtotime($firstday);//当前日期时间戳
$firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)-1).'-01'));//上个月开始的日期
$lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));//上个月结束的日期
$stimestamp = strtotime($firstday);
$etimestamp = strtotime($lastday);// 计算日期段内有多少天
$days = ($etimestamp-$stimestamp)/86400+1;// 保存每天日期
$date = array();
for($i=0; $i<$days; $i++){
$date[] = date('Y-m-d', $stimestamp+(86400*$i));
}