php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78758 DateTime format result is incorrect
Submitted: 2019-10-29 07:30 UTC Modified: 2019-10-29 07:57 UTC
From: checgg at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.1.33 OS: Any
Private report: No CVE-ID: None
 [2019-10-29 07:30 UTC] checgg at gmail dot com
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-10-29 07:42 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-10-29 07:54 UTC] checgg at gmail dot com
What is the `I` means ?

the result is :
```
string(21) "2019-10-27 02:55:00 1"
string(21) "2019-10-27 02:55:00 0"
```
'2019-10-27 08:55:00' transfer to "2019-10-27 02:55:00" is incorrect.
correct result should be "2019-10-27 01:55:00" ?
 [2019-10-29 07:57 UTC] requinix@php.net
https://www.php.net/date
> I (capital i)
> Whether or not the date is in daylight saving time
> 1 if Daylight Saving Time, 0 otherwise.

https://www.google.com/search?q=what+is+daylight+saving+time
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 02:01:30 2024 UTC