note 119362 added to datetime.createfromformat
| From: | lsloan-php dot net at umich dot edu | Date: | Fri, 20 May 2016 19:37:48 +0000 |
| Subject: | note 119362 added to datetime.createfromformat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205527@lists.php.net to get a copy of this message | ||
Reportedly, microtime() may return a timestamp number without a fractional part if the microseconds
are exactly zero. I.e., "1463772747" instead of the expected
"1463772747.000000". number_format() can create a correct string representation of the
microsecond timestamp every time, which can be useful for creating DateTime objects when used with
DateTime::createFromFormat():
<?php
$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.',
''));
var_dump($now->format('Y-m-d H:i:s.u')); // E.g., string(26) "2016-05-20
19:36:26.900794"
----
Server IP: 72.52.91.14
Probable Submitter: 35.2.149.67
----
Manual Page -- http://php.net/manual/en/datetime.createfromformat.php
Edit -- https://master.php.net/note/edit/119362
Del: integrated -- https://master.php.net/note/delete/119362/integrated
Del: useless -- https://master.php.net/note/delete/119362/useless
Del: bad code -- https://master.php.net/note/delete/119362/bad+code
Del: spam -- https://master.php.net/note/delete/119362/spam
Del: non-english -- https://master.php.net/note/delete/119362/non-english
Del: in docs -- https://master.php.net/note/delete/119362/in+docs
Del: other reasons-- https://master.php.net/note/delete/119362
Reject -- https://master.php.net/note/reject/119362
Search -- https://master.php.net/manage/user-notes.php