关于date函数z参数跟闰年的疑问

WBOY
Release: 2016-06-13 13:12:51
Original
1033 people have browsed it

关于date函数z参数和闰年的疑问
之前有写过关于是否为闰年的代码,闰年366天。

今天用date函数的时候看到有个参数‘z’(输出年份中的第几天),就用date写了个简易的闰年判断,代码如下
/**
 * 输出给定的年份是否为闰年
 * @param string $year
 */
function printYear($year){
date_default_timezone_set('PRC');
$time = $year.'-12-31 23:59:59';
$day = date('z', strtotime($time));
  echo $day.'
';
if($day == 366){
echo $year,'年是闰年';
}else{
echo $year,'年不是闰年';
}
}
printYear('2000');

但是输出的结果是:
365
2000年不是闰年

这就有问题了。请大神给解疑一下 到底哪个地方出现的问题

------解决方案--------------------
23:59:59 表示这一天并没有过完

printYear('2001');

364
2001年不是闰年

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!