我有一个日历显示星期几的错误日期。更具体地说,它们比实际日期落后一天。
我做了很多研究,并使用了以下SO问题(php date('d') calculates same output for two consecutive days),但我不能让它在我的脚本上工作。
它目前正在显示10月26日的两次,从日期出现错误。
$firstday = mktime(0,0,0,$month,1,$year);
$day = date('Y-m-d',$firstday);
$fday = strtotime($day." last Sunday ",$firstday);
$currday_timestamp = mktime(0,0,0,date('m'),date('d'),date('Y'));
for($i=0;$i<7;$i++) {
$firstweek[$i]['id'] = date("Y-m-d",$fday+(86400 * $i));
$firstweek[$i]['val'] = date("d",$fday+(86400 * $i));
if($currday_timestamp > $fday+(86400 * $i)) {
$firstweek[$i]['flag'] = 1;
}
$secondweek[$i]['id'] = date("Y-m-d",$fday+(86400 * ($i+7)));
$secondweek[$i]['val'] = date("d",$fday+(86400 * ($i+7)));
if($currday_timestamp > $fday+(86400 * ($i+7))) {
$secondweek[$i]['flag'] = 1;
}
$thirdweek[$i]['id'] = date("Y-m-d",$fday+(86400 * ($i+14)));
$thirdweek[$i]['val'] = date("d",$fday+(86400 * ($i+14)));
if($currday_timestamp > $fday+(86400 * ($i+14))) {
$thirdweek[$i]['flag'] = 1;
}
$fourthweek[$i]['id'] = date("Y-m-d",$fday+(86400 * ($i+21)));
$fourthweek[$i]['val'] = date("d",$fday+(86400 * ($i+21)));
if($currday_timestamp > $fday+(86400 * ($i+21))) {
$fourthweek[$i]['flag'] = 1;
}
$fifthweek[$i]['id'] = date("Y-m-d",$fday+(86400 * ($i+28)));
$fifthweek[$i]['val'] = date("d",$fday+(86400 * ($i+28)));
if($currday_timestamp > $fday+(86400 * ($i+28))) {
$fifthweek[$i]['flag'] = 1;
}
$sixthweek[$i]['id'] = date("Y-m-d",$fday+(86400 * ($i+35)));
$sixthweek[$i]['val'] = date("d",$fday+(86400 * ($i+35)));
if($currday_timestamp > $fday+(86400 * ($i+35))) {
$sixthweek[$i]['flag'] = 1;
}
}
我如何解决这个闰秒问题?我需要在秒中添加一个值吗?
答案 0 :(得分:0)
听起来这与从夏令时到标准时间的变化有关。
最简单的方法是在基准时间内添加几个小时:
$time_offset = 2 * 60 * 60; // 2 hours
$firstday = mktime(0,0,0,$month,1,$year) + $time_offset;
$day = date('Y-m-d',$firstday);
$fday = strtotime($day." last Sunday ",$firstday) + $time_offset;
$currday_timestamp = mktime(0,0,0,date('m'),date('d'),date('Y')) + $time_offset;