|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-03-11 17:15 UTC] php at richardneill dot org
Description:
------------
The time expression "13:01 P.M." is technically malformed (it's tautologous), but people are still likely to use it sometimes. PHP mis-converts it, turning 13 into 16 !.
(In comparison, the Unix date command rejects it)
Test script:
---------------
PHP:
<?
echo date ("Y-m-d H:i:s", strtotime("13:01 P.M."));
#result: 2016-03-11 16:01:00
#expected: 2016-03-11 13:01:00
echo date ("Y-m-d H:i:s", strtotime("12:01 P.M."));
#result: 2016-03-11 12:01:00
#correct
?>
Shell:
$ date -d '13:01 P.M.';
date: invalid date ‘13:01 P.M.’
$ date -d '12:01 P.M.';
Fri Mar 11 12:01:00 GMT 2016
Expected result:
----------------
PHP shouldn't be off-by-3.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
Thanks - I had no idea that there even was such a thing as a military P timezone. My workaround, which may help anyone else, is just to do: str_replace (array ("a.m.","p.m."), array("am","pm"), strtolower($input)); before parsing with strtotime(). That way, "13:01 P.M." or "14:01 A.M." will always fail, rather than be valid-but-wrong. Correct use of am or pm is still fine.