|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-02-26 00:50 UTC] alexander dot minges at gmail dot com
Description:
------------
strtotime fails to parse strings in the format "Feb 25 23:38:22.226 2015 GMT" while "Feb 25 23:38:22 2015 GMT" is parsed fine. The same applies to creating a DateTime object.
Test script:
---------------
<?php
//This works
echo strtotime("Feb 25 23:38:22 2015 GMT");
//This one does not
echo strtotime("Feb 25 23:38:22.226 2015 GMT");
?>
Expected result:
----------------
1424907502
1424907502
Actual result:
--------------
1424907502
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 17:00:01 2025 UTC |
The most it could do is ignore the microseconds. Meanwhile DateTime::createFromFormat("M d H:i:s.u Y T", "Feb 25 23:38:22.226 2015 GMT") works fine.I run into this issue just today, trying to parse ODS files with PHPExcel, where some properties contain a timestamp with many fractional digits. Apparently strtotime() always returns false if there are more than 7 decimals. For example: var_dump(strtotime("1970-01-02 00:00:00.000 GMT")); // int(86400), ok var_dump(strtotime("1970-01-02 00:00:00.00000000 GMT")); // expected: int(86400), got: bool(false)