谢谢你的回答,我结合了你的解决方案,它很有效!
human\\u time\\u diff,不适合我的脚本,因为它的返回时间是分钟、小时和天,带有“ago”字样。因此,我创建了自己的函数,该函数只返回天,没有“ago”。
功能代码:
function count_days($from){
$start_time = $from;
$current_time = time();
//convert given date to the unix time (in seconds)
$unix_start_time = date("U",strtotime($start_time));
//count the difference between current time and given date
$diff = (int) abs($current_time - $unix_start_time);
//Now, we change seconds for days
if ($diff >= 86400) {
$days = round($diff / 86400);
if ($days <= 1) $days = 1;
}
//returns days
return $days;
}
函数的第一个参数是日期,例如22-09-2012。接下来,将该日期转换为unix秒,然后我们可以从该日期中减去当前时间。这样,我们可以计算自给定日期以来经过的天数。耶!
再次感谢!