#1 小双
class seday{
function daysInSpan($start,$end){
$dayTicks=$this->ticksInDay();
return ($end-$start)/$dayTicks;
}
function ticksInDay(){
$today=getdate();
$yesterday=mktime(0,0,0,$today[mon],$today[mday]-1,$today[year]);
$today=mktime(0,0,0,$today[mon],$today[mday],$today[year]);
return $today-$yesterday;
}
function day($dayone,$daytwo){
$start_time_array=explode("/",$dayone);
$endtime_time_array=explode("/",$daytwo);
$start_time_year=$start_time_array[0];
$start_time_month=$start_time_array[1];
$start_time_day=$start_time_array[2];
$end_time_year=$endtime_time_array[0];
$end_time_month=$endtime_time_array[1];
$end_time_day=$endtime_time_array[2];
return $this->daysInSpan(mktime(0,0,0,$start_time_month,$start_time_day,0+$start_time_year),
mktime(0,0,0,$end_time_month,$end_time_day,0+$end_time_year)
);
}
}
调用方法:
import("seday.php");
$seday = new seday;
$dayCount = $seday->day("2009/02/23","2009/04/23");
dump($dayCount);
2010-07-28 09:12:23