PHP calculate time difference

不言
Release: 2023-03-23 22:50:02
Original
2176 people have browsed it

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;    
   }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!