note 129144 added to datetime.createfromformat
| From: | mariani dot v at sfeir dot com | Date: | Fri, 05 Jan 2024 14:13:16 +0000 |
| Subject: | note 129144 added to datetime.createfromformat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221098@lists.php.net to get a copy of this message | ||
An easiest way to avoid error when microtime returns a non decimal float is to cast its result as a
float using sprintf :
$t = microtime(true);
$now = DateTime::createFromFormat('U.u', sprintf('%f', $t));
$now = $now->format("H:i:s.v");
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 84.14.204.196)
----
Manual Page -- https://php.net/manual/en/datetime.createfromformat.php
Edit -- https://main.php.net/note/edit/129144
Del: integrated -- https://main.php.net/note/delete/129144/integrated
Del: useless -- https://main.php.net/note/delete/129144/useless
Del: bad code -- https://main.php.net/note/delete/129144/bad+code
Del: spam -- https://main.php.net/note/delete/129144/spam
Del: non-english -- https://main.php.net/note/delete/129144/non-english
Del: in docs -- https://main.php.net/note/delete/129144/in+docs
Del: other reasons-- https://main.php.net/note/delete/129144
Reject -- https://main.php.net/note/reject/129144
Search -- https://main.php.net/manage/user-notes.php