The udate function is a great start, but the formatting of the milliseconds is a little off. If it is within the first 100000 microseconds then the string will be less than 6 characters, so 0.012435 will appear as 0.12345. The revision below fixes this.
function udate($strFormat = 'u', $uTimeStamp = null)
{
// If the time wasn't provided then fill it in
if (is_null($uTimeStamp))
{
$uTimeStamp = microtime(true);
}
// Round the time down to the second
$dtTimeStamp = floor($uTimeStamp);
// Determine the millisecond value
$intMilliseconds = round(($uTimeStamp - $dtTimeStamp) * 1000000);
// Format the milliseconds as a 6 character string
$strMilliseconds = str_pad($intMilliseconds, 6, '0', STR_PAD_LEFT);
// Replace the milliseconds in the date format string
// Then use the date function to process the rest of the string
return date(preg_replace('`(?<!\\\\)u`', $strMilliseconds, $strFormat), $dtTimeStamp);
}