Bug #74275 [Com]: strtotime()
| From: | danack@php.net | Date: | Tue, 21 Mar 2017 13:46:29 +0000 |
| Subject: | Bug #74275 [Com]: strtotime() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207979@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74275&edit=1
ID: 74275
Comment by: danack@php.net
Reported by: 252811115 at qq dot com
Summary: strtotime()
Status: Open
Type: Bug
Package: Date/time related
Operating System: window,linux
PHP Version: 7.1.3
Block user comment: N
Private report: N
New Comment:
To me, 00:59pm doesn't look like a valid time.
Hours in a 12-hour format time have the range 1-12.
Hours in a 24-hour format time have the range 0-23.
Obviously the behaviour of strtotime here is unexpected, but you've passed it something that
doesn't look like a valid timestamp, so there may not be a 'correct' behaviour for it
to follow.
Previous Comments:
------------------------------------------------------------------------
[2017-03-20 03:24:16] 252811115 at qq dot com
Description:
------------
if time is 00:00am to 00:59am
or 00:00pm to 00:59pm
strtotime()
Test script:
---------------
<?php
$time1 = '5:20am';
$time2 = '12:55pm';
$time3 = '9:55pm';
$time4 = '0:45pm';
$date = date('Y-m-d');
echo date('Y-m-d H:i:s',strtotime($date.$time1)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time2)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time3)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time4)).PHP_EOL;
?>
2017-03-20 05:20:00
2017-03-20 12:55:00
2017-03-20 21:55:00
1970-01-01 08:00:00
Expected result:
----------------
<?php
$time1 = '5:20am';
$time2 = '12:55pm';
$time3 = '9:55pm';
$time4 = '0:45pm';
$date = date('Y-m-d');
echo date('Y-m-d H:i:s',strtotime($date.$time1)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time2)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time3)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time4)).PHP_EOL;
?>
Actual result:
--------------
2017-03-20 05:20:00
2017-03-20 12:55:00
2017-03-20 21:55:00
1970-01-01 08:00:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74275&edit=1