我有这段代码:
$expiration_date='2041-07-14'
$epoch_timestamp_expiration_date = strtotime($expiration_date);
//Get 7 days
$seven_days_ago=7*86400;
//subtract seven days from the expiration date.
$epoch_timestamp_expiration_date-=$seven_days_ago;
//Format the new expiration date - 7 days ago
$formatted_epoch_time=date('Y-m-d',$epoch_timestamp_expiration_date);
//Todays format.
$today=date('Y-m-d', time());
//Todays miliseconds
$today_secs=strtotime($today);
//Subtracting expiration date in epoch secs from todays secs
$diff_secs = abs($epoch_timestamp_expiration_date-$today_secs);
//Finding the number of days between the two
$days=floor($diff_secs/86400);
//Printing output
echo "<br/><br/>Days: ". $days;
echo "<br/><br/>Today: ".$today;
echo "<br/><br/>Expiration Date : ".$expiration_date;
echo "<br/><br/>Expiration Date 7 days ago: ".$formatted_epoch_time ;
//Is cache near to expire. 7 days closer to the expiration date.
if ($epoch_timestamp_expiration_date>$today_secs) {
echo "<br/><br/>The site isnt about to expire ";
return "<br/><br/>Cache date isnt about to expire ".$days;
}
当输出得到回应时,我得到了这个:
Days: 15634
今天:2012-10-14
有效期:2041-07-14
失效日期7天前:1969-12-25
为什么?
现在,如果我将值交换参数:
$expiration_date='2013-07-14';
我明白了:
天数:266
今天:2012-10-14
到期日期:2013-07-14
截止日期7天前:2013-07-07
该网站不会过期
答案 0 :(得分:5)
这是因为expiration_date超出了Unix时间戳(2038-01-19): http://en.wikipedia.org/wiki/Unix_time
http://php.net/manual/en/function.date.php
“时间戳的有效范围通常是格林威治标准时间1901年12月13日20:45:54格林威治标准时间2038年1月19日星期二03:14:07 GMT。(这些是与最小值和最大值对应的日期但是,在PHP 5.1.0之前,在某些系统(例如Windows)上,此范围限制在01-01-1970到19-01-2038之间。“