我有这个代码:
$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
该网站不会过期
这是因为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 GMT 到 2038 年 1 月 19 日星期二 03:14:07 GMT。(这些日期对应于 32 位有符号整数的最小值和最大值)。但是,在 PHP 5.1.0 之前,在某些系统(例如 Windows)上,此范围从 01-01-1970 限制为 19-01-2038。