Jump to content

Get date and time from microtime


spaze

Recommended Posts

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

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.