如何在PHP中以ms为单位获取当前时间?

What I want to get is the very like time(),but should be accurate in ms:

2010-11-15 21:21:00:987

Is that possible in PHP?

function udate($format, $utimestamp = null) {
  if (is_null($utimestamp))
    $utimestamp = microtime(true);

  $timestamp = floor($utimestamp);
  $milliseconds = round(($utimestamp - $timestamp) * 1000000);

  return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);
}

echo udate('Y-m-d H:i:s:u'); // 2010-11-15 21:21:00:987

Use the microtime() function.

See the manual page here: http://php.net/manual/en/function.microtime.php

[EDIT] To get the output in year/month/day/hour/minutes/seconds/ms as requested:

Try something like this:

list($usec, $sec) = explode(" ", microtime());
$output = date('Y/m/d H:i:s',$sec). " /" . $usec;

Again, see the manual page for more details on how microtime() works.

Use microtime and convert it to milliseconds:

$millitime = round(microtime(true) * 1000);

Take a look at php's microtime function.

This is my way

list($usec, $sec) = explode(" ", microtime());
$time =  date("Y-m-d H:i:s:",$sec).intval(round($usec*1000));
echo $time;