|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-11-24 10:57 UTC] jani@php.net
-Package: Feature/Change Request
+Package: Date/time related
[2016-10-05 20:14 UTC] derick@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: derick
[2016-10-05 20:14 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 13:00:01 2025 UTC |
Description: ------------ Currently the DateTime object construction accepts a strtotime type input only for setting the date on the object. This means that when trying to get the current time WITH microseconds you have to do something like this.. <?php $t = microtime(true); $micro = sprintf("%06d",($t - floor($t)) * 1000000); $d = new DateTime( date('Y-m-d H:i:s.'.$micro,$t) ); ?> which is highly inefficient as we are converting a float into a string and then converting it from a string into the internal format for the DateTime object. It would be really nice to have a constructor for the DateTime object that would accept a float argument (defaulting to NOW w/ microseconds) Possible suggestions would be factory method $d = DateTime::TimeWithMicroseconds(); make the constructor accept a float $d = new DateTime(microtime(true)); modify the setTimestamp method in PHP 5.3 to accept a float. $d = new DateTime(); $d->setTimestamp(microtime(true));