4求两个日期的差数,例如2007-2-5 ~ 2007-3-6 的日期差数
解析: <pre ><code class=方法一: <?php class Dtime { function get_days($date1, $date2) { $time1 = strtotime($date1); $time2 = strtotime($date2); return ($time2-$time1)/86400; } } $Dtime = new Dtime; echo $Dtime->get_days(’2007-2-5′, ’2007-3-6′); ?> 方法二: <?php $temp = explode(‘-’, ’2007-2-5′); $time1 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]); $temp = explode(‘-’, ’2007-3-6′); $time2 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]); echo ($time2-$time1)/86400; 方法三:echo abs(strtotime(“2007-2-1″)-strtotime(“2007-3-1″))/60/60/24 计算时间差"php hljs">方法一: <?php class Dtime { function get_days($date1, $date2) { $time1 = strtotime($date1); $time2 = strtotime($date2); return ($time2-$time1)/86400; } } $Dtime = new Dtime; echo $Dtime->get_days(’2007-2-5′, ’2007-3-6′); ?> 方法二: <?php $temp = explode(‘-’, ’2007-2-5′); $time1 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]); $temp = explode(‘-’, ’2007-3-6′); $time2 = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]); echo ($time2-$time1)/86400; 方法三:echo abs(strtotime(“2007-2-1″)-strtotime(“2007-3-1″))/60/60/24 计算时间差</code></pre>
点击加载更多评论>>