Get time difference [duplicate]
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);
精彩评论