Home  >  Article  >  Backend Development  >  PHP calculate time difference

PHP calculate time difference

不言
不言Original
2018-04-16 13:51:122232browse

The main content of this article is about PHP calculation time difference, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

   function getTime($startdate,$enddate){        
   $startdate = strtotime('2017-01-01 12:12:12');        
   $enddate = strtotime('2017-01-02 13:13:13');        
   $date=floor(($enddate-$startdate)/86400);
//        echo "相差天数:".$date."天<br/><br/>";        
   $hour=floor(($enddate-$startdate)%86400/3600);
//        echo "相差小时数:".$hour."小时<br/><br/>";        
   $minute=floor(($enddate-$startdate)%86400%3600/60);
//        echo "相差分钟数:".$minute."分钟<br/><br/>";        
   $second=floor(($enddate-$startdate)%86400%3600%60);
//        echo "相差秒数:".$second."秒";        
   return $date*24+$hour.'小时'.$minute.'分'.$second;    
   }

Related recommendations:

php example code for calculating the lunar calendar

PHP calculates the stability of student grades

PHP calculates cosine similarity algorithm example

The above is the detailed content of PHP calculate time difference. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP version coexistenceNext article:PHP version coexistence