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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.