Bug #77885 [Nab]: DateTime function is taking timezone in consideration and always considering se

From: Date: Fri, 12 Apr 2019 20:34:58 +0000
Subject: Bug #77885 [Nab]: DateTime function is taking timezone in consideration and always considering se
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220425@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77885&edit=1 ID: 77885 Updated by: requinix@php.net Reported by: vinodh dot basavani at darwinbox dot io Summary: DateTime function is taking timezone in consideration and always considering se Status: Not a bug Type: Bug Package: PHP options/info functions Operating System: Debian GNU/Linux 9.8 (stretch) PHP Version: 7.1.28 Block user comment: N Private report: N New Comment: What does date_default_timezone_get() return? Previous Comments: ------------------------------------------------------------------------ [2019-04-12 20:33:24] vinodh dot basavani at darwinbox dot io No..its in IST time zone. ------------------------------------------------------------------------ [2019-04-12 20:32:25] requinix@php.net You know the default timezone in PHP is UTC, right? ------------------------------------------------------------------------ [2019-04-12 20:30:20] vinodh dot basavani at darwinbox dot io $dt = new DateTime("1970-01-01 ".date("H:i:s"), new DateTimeZone('UTC')); $seconds = (int)$dt->getTimestamp(); echo date("H:i:s",$seconds); This snippet works fine in earlier versions of php i.e it is not taking the server time zone. but when i updated to the specified version. it is always taking the server time and ignoring the timezone specified. ------------------------------------------------------------------------ [2019-04-12 20:24:26] requinix@php.net That is not how timezones and Unix timestamps work. You created a date and time according to the server timezone. Changing the timezone from there only affects the string representation of it - the timestamp is the same. Getting that timestamp and formatting it according to the server timezone will get you right back to where you started. ------------------------------------------------------------------------ [2019-04-12 20:01:51] vinodh dot basavani at darwinbox dot io Description: ------------ <?php $dt = new DateTime("1970-01-01 ".date("H:i:s")); $dt->setTimezone(new DateTimeZone('UTC')); echo $dt->format('r'); echo "\n"; $seconds = (int)$dt->getTimestamp(); echo date("H:i:s",$seconds); echo "\n"; ?> even if i am setting the timezone to UTC, it is taking only the server time. Expected result: ---------------- It should take the UTC time zone. Actual result: -------------- It should take the UTC time zone. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77885&edit=1

« previous php.bugs (#220425) next »