Be careful using UTCDateTime if you need microsecond precision as this class only stores time to the _millisecond_. You need to store the date as a string in MongoDB if you want the full precision. Casting DateTime to a float can also remove precision.
An easy way to see the differences is with:
Code:
var_dump(
(new DateTime)->format('U.u'),
(float) (new DateTime)->format('U.u'),
(new MongoDB\BSON\UTCDateTime())->toDateTime()->format('U.u')
);
Output:
string(17) "1477534060.918415"
double(1477534060.9185)
string(17) "1477534060.918000"
NOTE: Lots of bugs concerning microsecond formatting for DateTimeInterface classes were fixed as of PHP 7.1.0 RC4. The above code is from PHP 7.1.0 RC5 and mongodb 1.2.0alpha3. The 1.2.0 version of the extension added the ability to instantiate this class without passing integer milliseconds.