PHP生成某个范围内的随机时间
/**
* 生成某个范围内的随机时间
* @param $begintime 时间 格式为 Y-m-d H:i:s
* @return string 生成新的时间
*/
function randomDate($begintime,$time=60) {
$end = strtotime($begintime);
$begin = strtotime(date('Y-m-d H:i:s')) - $time;
$timestamp = rand($begin, $end);
return date("Y-m-d H:i:s", $timestamp);
}
调用接口
//生成当前时间前1分钟内的随机时间
$this->randomDate(date('Y-m-d H:i:s', time()),60);