Core code:
Class Utils {/** * format mysql DateTime (yyyy-mm-dd hh:mm:ss) converts the data format found in MySQL into time seconds * @param string $datetim
E/Public Function fmdatetime ($datetime) {$year = substr ($datetime, 0,4);
$month = substr ($datetime, 5,2);
$day = substr ($datetime, 8,2);
$hour = substr ($datetime, 11,2);
$min = substr ($datetime, 14,2);
$sec = substr ($datetime, 17,2);
Return Mktime ($hour, $min, $sec, $month, $day, 0+ $year);
/** * * * The number of years, months, days, hours, minutes, seconds * @param string $start * @param string $end * @return Arrayobject based on two times
* * Private Function Diffdatetime ($DateStart, $DateEnd) {$rs = array ();
$sYear = substr ($DateStart, 0,4);
$eYear = substr ($DateEnd, 0,4);
$sMonth = substr ($DateStart, 5,2);
$eMonth = substr ($DateEnd, 5,2);
$sDay = substr ($DateStart, 8,2);
$eDay = substr ($DateEnd, 8,2);
$startTime = $this->fmdatetime ($DateStart);
$endTime = $this->fmdatetime ($DateEnd); $dis = $endTime-$startTime///The number of seconds to get two times $d = Ceil ($dis/(24*60*60)//Get the number of days $rs [' Day '] = $d;//Days $rs [' hour '] = Ceil ($dis/(60*60));/hour $rs [' minute '] = ceil ($dis/60);/min $rs [' second '] = $dis;//sec $rs [' Week '] = ceil ($d/7);/Week $tem = ($eYear-$sYear) *12;//month $tem 1 = $eYear-$sYear;//year if ($eMonth-$sMonth <0)
{//month subtraction is negative $tem + = ($eMonth-$sMonth);
}else if ($eMonth = = $sMonth) {//month same if ($eDay-$sDay >=0) {$tem + +;
$tem 1++;
}else if ($eMonth-$sMonth >0) {//month subtraction positive $tem 1++;
if ($eDay-$sDay >=0) {//and the date is subtracted to a positive number $tem + = ($eMonth-$sMonth) +1;
}else{$tem + + ($eMonth-$sMonth);
}} $rs [' month '] = $tem;
$rs [' year '] = $tem 1;
return $rs;
}
}
More than a year, the return is 2 years, one months more than a day to return 2 months, to push ... Project needs to do this out, I also went online to find such an example, but everyone is the year on the basis of 365 days, the month on the basis of 30 days to calculate, so that the results are certainly useless, the year may be 366 days, the month may be 31,29,28 may be the