开发者

Get time difference [duplicate]

开发者 https://www.devze.com 2023-03-10 11:16 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Get time difference Hi, i need to get time difference between two time in php.
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Get time difference

Hi, i need to get time difference between two time in php.

$starttime=time();
$endtime=time开发者_如何学Go();

how to get hour minute and second in php

thanks


echo ($endtime-$starttime);

Will get you the number of seconds.

If you need to know the hours you can do something like:

$seconds = ($endtime-$starttime);
echo floor($seconds/3600).' hours';


$starttime=time();
$endtime=time();

$diff = $endtime - $starttime;
$hours = floor($diff / 3600);
$minutes = floor (($diff % 3600) / 60);
$seconds = $diff % 60;


you can use date_diff for this....


Take a look at strftime

$difference = $endtime-$starttime;
echo strftime('%H:%M:%S',$difference);
0

精彩评论

暂无评论...
验证码 换一张
取 消