开发者

Get time difference [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜