标签:
碰到一个需求,要计算活动开始后的第几天~
方案一:date_diff()函数 ,但要求php版本5.3+
$date1=date_create("2015-11-02"); $date2=date_create(date(‘Y-m-d‘,time())); $diff=date_diff($date1,$date2); $has_start = $diff->days + 1; echo $count_day = 10000 * pow($has_start, 2); var_dump($diff); // echo $diff->format("%R%a days");
方案二: strtotime(),所有版本即可,但2035年是一个坎,int型溢出问题
$start_day = "2015-11-04"; $cur_day = date(‘Y-m-d‘,time()); $start_time = strtotime($start_day); $cur_time = strtotime($cur_day); $diff = $cur_time - $start_time; $diff_day = ceil($diff/3600/24) + 1; $d=ceil($diff/3600/24); $h=ceil($diff%(3600/24)/3600); $m=ceil($diff%(3600/24)/60); echo "相差$d天$h小时$m分";
标签:
原文地址:http://www.cnblogs.com/zhongyuan/p/4935436.html