我有这个代码:
$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
网站不会过期