How to subtract microtime and display date with milliseconds in php?

前端 未结 2 2076
死守一世寂寞
死守一世寂寞 2020-12-10 13:02

How to subtract microtime and display date with milliseconds in php ?

For example: I have set end date and time

$endtime = 2012-02-21 10:29:59;
         


        
2条回答
  •  离开以前
    2020-12-10 13:34

    Well phpmyadmin uses this a code like this to calculate the time that a query took. It's similar to your requirements:

    //time before
    list($usec, $sec) = explode(' ',microtime($starttime));
    $querytime_before = ((float)$usec + (float)$sec);
    /* your code */
    
    //time after
    list($usec, $sec) = explode(' ',microtime($endtime));
    $querytime_after = ((float)$usec + (float)$sec);
    $querytime = $querytime_after - $querytime_before;
    

    I think this should work for you. You just have to figure your output format

提交回复
热议问题