经测试代码如下:
/**
* 计算日期几天后
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
public static function subDate($day,$date = "",$timestampFlag = true,$format = "Y-m-d H:i:s") {
if (empty($date)) {
$now = time();
} else {
注释: 不是时间截格式,是YYYY-mm-dd HH:ii:ss格式,将它们转换成时间戳格式
if (!is_numeric($date)) {
$datetime_array = explode(" ",$date);
$date_array = explode("-",$datetime_array[0]);
$time_array = explode(":",$datetime_array[1]);
$now = mktime($time_array[0],$time_array[1],$time_array[2],$date_array[1],$date_array[2],$date_array[0]);
} else {
$now = $date;
}
}
$m = $day * 24 * 60 * 60;
$diff = $now + $m;
if ($timestampFlag) {
return $diff;
} else {
if (empty($format)) $format = "Y-m-d H:i:s";
$oldday = date($format,$diff);
return $oldday;
}
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/