php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73071 Datime::createFromFormat timezone bug
Submitted: 2016-09-13 16:02 UTC Modified: 2016-09-13 16:12 UTC
From: tmcoder at qq dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.25 OS: CentOS Linux release 7.2.1511
Private report: No CVE-ID: None
 [2016-09-13 16:02 UTC] tmcoder at qq dot com
Description:
------------
---versions---
5.6.25、7.0.6

---Description---
public static DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone = date_default_timezone_get() ] )

When format option contain a microsecond string like 'U.u', the tiemzone option is invalid. 


Test script:
---------------
<?php
$timezone = new \DateTimeZone('PRC'); 
$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''), $timezone);
print_r($now);
$now->setTimezone($timezone);
print_r($now);
?>

Expected result:
----------------
two results should be equal

Actual result:
--------------
Two results are not equal

DateTime Object
(
    [date] => 2016-09-13 15:55:50.946395
    [timezone_type] => 1
    [timezone] => +00:00
)
DateTime Object
(
    [date] => 2016-09-13 23:55:50.946395
    [timezone_type] => 3
    [timezone] => PRC
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-13 16:12 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-09-13 16:12 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://php.net/manual/en/datetime.createfromformat.php
> Note:
> The timezone parameter and the current timezone are ignored when the time
> parameter either contains a UNIX timestamp (e.g. 946684800) or specifies a
> timezone (e.g. 2010-01-28T15:00:00+02:00).
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 17:00:02 2026 UTC