Bug #78758 [NEW]: DateTime format result is incorrect
| From: | checgg at gmail dot com | Date: | Tue, 29 Oct 2019 07:30:46 +0000 |
| Subject: | Bug #78758 [NEW]: DateTime format result is incorrect | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-223496@lists.php.net to get a copy of this message | ||
From: checgg at gmail dot com
Operating system: Any
PHP version: 7.1.33
Package: Date/time related
Bug Type: Bug
Bug description:DateTime format result is incorrect
Description:
------------
var_dump(test('2019-10-27 08:55:00'));//result is 2019-10-27 02:55:00
var_dump(test('2019-10-27 09:55:00'));//result is also 2019-10-27
02:55:00
It`s incorrect.
Test script:
---------------
<?php
ini_set('date.timezone', 'Asia/Shanghai');
var_dump(test('2019-10-27 08:55:00'));//result is 2019-10-27 02:55:00
var_dump(test('2019-10-27 09:55:00'));//result is also 2019-10-27
02:55:00
function test($testDate)
{
$format = 'Y-m-d H:i:s';
$timezone = 'Europe/Paris';
// if ($timezone == 'Europe/Paris') {
// return date($format, strtotime($testDate) - 7 * 3600);
// }
$date = new DateTime($testDate);
$date->setTimezone(new DateTimeZone($timezone));
return $date->format($format);
}
Expected result:
----------------
var_dump(test('2019-10-27 08:55:00'));//result is 2019-10-27 01:55:00
var_dump(test('2019-10-27 09:55:00'));//result is also 2019-10-27
02:55:00
It`s correct.
Actual result:
--------------
var_dump(test('2019-10-27 08:55:00'));//result is 2019-10-27 02:55:00
var_dump(test('2019-10-27 09:55:00'));//result is also 2019-10-27
02:55:00
It`s incorrect.
--
Edit bug report at https://bugs.php.net/bug.php?id=78758&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78758&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78758&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78758&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78758&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78758&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78758&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78758&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78758&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78758&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78758&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78758&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78758&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78758&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78758&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78758&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78758&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78758&r=mysqlcfg