Req #69122 [Com]: strtotime and DateTime fail to parse certain strings with fractional seconds
| From: | cafdaf at outlook dot com | Date: | Mon, 25 Oct 2021 19:35:20 +0000 |
| Subject: | Req #69122 [Com]: strtotime and DateTime fail to parse certain strings with fractional seconds | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237376@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69122&edit=1
ID: 69122
Comment by: cafdaf at outlook dot com
Reported by: alexander dot minges at gmail dot com
Summary: strtotime and DateTime fail to parse certain strings
with fractional seconds
Status: Open
Type: Feature/Change Request
Package: Date/time related
Operating System: Linux 3.18.7 x86_64 GNU/Lin
PHP Version: 5.6.6
Block user comment: N
Private report: N
New Comment:
داÙÙÙØ¯ اÙÙÚ¯ Ø¬Ø¯ÛØ¯ Ø§ÛØ±Ø§ÙÛ Ø±Ø§
Ù
ÛâØªÙØ§Ù Ø¨Ø®Ø´Û Ø§Ø² Ù¾Ûکر٠بزرگ
داÙÙÙØ¯ Ø¢ÙÙÚ¯âÙØ§Û Ø¬Ø¯ÛØ¯ تÙÙÛ
کرد. ÙÛØ§Ø²Û Ú©Ù Ø®ÙØ´Ø¨Ø®ØªØ§ÙÙ
زÙ
ÛÙÙ Ø¨Ø±Ø¢ÙØ±Ø¯ÙâØ³Ø§Ø²Û Ù Ø±Ø´Ø¯ Ø¢Ù
در ساÙâÙØ§Û Ø§Ø®ÛØ± بÙâØ®ÙØ¨Û
ÙØ±Ø§ÙÙ
Ø¢Ù
د٠است. Ø®ÙØ´Ø¨Ø®ØªØ§ÙÙØ
ازآÙâØ¬ÙØª Ú©Ù Ø¨Ø§ØªÙØ¬ÙâØ¨Ù ÙÛØ§Ø²
Ø±ÙØÛ Ø§ÙØ±Ø§Ø¯ ب٠Ù
ÙØ²ÛÚ© ٠آراÙ
Ø´
بÛâÙØ¸Ûر ØØ§ØµÙ از
Ú¯ÙØ´âÙØ±Ø§Ø¯Ø§Ø¯Ù ب٠آÙÙÚ¯ ÙØ§Û
Ø¬Ø¯ÛØ¯Ø Ú©Ù
تر Ù
ÙØ±Ø¯Û را Ù
ÛâØªÙØ§Ù
جاÛگزÛ٠آ٠ÙÙ
ÙØ¯.
https://ahang.cafe/داÙÙÙØ¯-تک-Ø¢ÙÙÚ¯/
Previous Comments:
------------------------------------------------------------------------
[2016-01-12 08:43:49] salsi at icosaedro dot it
Related To: Bug #71345
------------------------------------------------------------------------
[2015-09-27 09:59:35] salsi at icosaedro dot it
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)
------------------------------------------------------------------------
[2015-02-26 01:03:51] requinix@php.net
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.
------------------------------------------------------------------------
[2015-02-26 00:50:51] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69122&edit=1