Hello, I have problem with date timezone. Running Windows 10, PHP 7.1.10.
When I use this code:
date_default_timezone_set('UTC');
var_dump(new \DateTime("2018-09-01", new \DateTimeZone(date_default_timezone_get())));
var_dump(new \DateTime("2018-09-01"));
date_default_timezone_set('CET');
var_dump(new \DateTime("2018-09-01", new \DateTimeZone(date_default_timezone_get())));
var_dump(new \DateTime("2018-09-01"));
The output is:
object(DateTime)#692 (3) {
["date"]=>
string(26) "2018-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#692 (3) {
["date"]=>
string(26) "2018-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "UTC"
}
object(DateTime)#692 (3) {
["date"]=>
string(26) "2018-09-01 00:00:00.000000"
["timezone_type"]=>
int(2)
["timezone"]=>
string(3) "CET"
}
object(DateTime)#692 (3) {
["date"]=>
string(26) "2018-09-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(3) "CET"
}
So, if I use UTC
as timezone, result is same for creating DateTime with or without specifying second parameter (timezone). But when I use CET
as timezone, results differs in timezone_type
.
My question is, it’s a PHP bug, or when I must use second parameter (not null value), what is right value to get same result as without second parameter?