PHP gets the year, month, day, hour, minute, second of the specified time period, PHP gets
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 $datetime */pu Blic 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);} /** * * * * * * * * * * * * * * * * * for two time inclusive years, months, days, hours, minutes, seconds * @param string $start * @param string $end * @return Arrayobject */Private F Unction 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;//Get two time seconds $d = Ceil ($dis/(24*60*60));//Get Days $rs[' Day ' = $d;//Days $rs[' hour '] = Ceil ($dis/(60*60)) ;//Hours $rs[' minute ']= Ceil ($dis/60);//min $rs[' second '] = $dis;//Seconds $rs[' Week '] = ceil ($d/7);//week $tem = ($eYear-$sYear) *12;//Month $tem1 = $eYear-$ syear;//if ($eMonth-$sMonth <0) {//month subtracts negative $tem + = ($eMonth-$sMonth);} else if ($eMonth = = $sMonth) {//month same if ($eDay-$sDay >=0) {$tem + +; $tem 1++;}} else if ($eMonth-$sMonth >0) {//month minus $tem1++;if ($eDay-$sDay >=0) {//and date subtracted to positive $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 is 2 months, to push ... Project needs, just do this out, I also go to the Internet to find such an example, but everyone is the year on the basis of 365 days to calculate, the month according to 30 days to calculate, so that the results are certainly useless, the year may be 366 days, the month may be 31,29,28 are possible
http://www.bkjia.com/PHPjc/1133018.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133018.html techarticle PHP Gets the core code for the year, month, day, hour, minute, and second, PHP gets the specified time period: Class Utils {/** * format mysql DateTime (yyyy-mm-dd hh:mm:ss) to find out the data in MySQL. .