spaze Posted November 3, 2009 Share Posted November 3, 2009 I use the following function to get microtime: function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } How can I get date and time in microseconds? Link to comment https://forums.phpfreaks.com/topic/180159-get-date-and-time-from-microtime/ Share on other sites More sharing options...
salathe Posted November 3, 2009 Share Posted November 3, 2009 You can use the date function to get the date in whatever format you like. Link to comment https://forums.phpfreaks.com/topic/180159-get-date-and-time-from-microtime/#findComment-950507 Share on other sites More sharing options...
Psycho Posted November 3, 2009 Share Posted November 3, 2009 function microDateTime() { list($microSec, $timeStamp) = explode(" ", microtime()); return date('F jS, Y, H:i:', $timeStamp) . (date('s', $timeStamp) + $microSec); } echo microDateTime(); //Output: November 3rd, 2009, 15:38:38.671753 Modify format as needed Link to comment https://forums.phpfreaks.com/topic/180159-get-date-and-time-from-microtime/#findComment-950528 Share on other sites More sharing options...
Mchl Posted November 3, 2009 Share Posted November 3, 2009 Just a thought. We use microtime, to get time reading with microsecond precision, but by enclosing microtime in function, we actually delay it's execution (how much?). Wouldn't it be more logical, to call microtime externally and pass it's result to the function that would do formatting only? Link to comment https://forums.phpfreaks.com/topic/180159-get-date-and-time-from-microtime/#findComment-950532 Share on other sites More sharing options...
Psycho Posted November 3, 2009 Share Posted November 3, 2009 Just a thought. We use microtime, to get time reading with microsecond precision, but by enclosing microtime in function, we actually delay it's execution (how much?). Wouldn't it be more logical, to call microtime externally and pass it's result to the function that would do formatting only? Good point. I guess it depends on what the purpose is. If I was running some start and end times of a process to gather metrics on performance I would probably include the microtime call int he function itself. Since each start and stop would have to call the function, the time to start the function should be "equivalent" if not for the single instance it should be over the long term. Link to comment https://forums.phpfreaks.com/topic/180159-get-date-and-time-from-microtime/#findComment-950552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.