note 117514 added to datetime.settimezone

From: Date: Mon, 22 Jun 2015 11:16:01 +0000
Subject: note 117514 added to datetime.settimezone
Groups: php.notes 
Request: Send a blank email to php-notes+get-202922@lists.php.net to get a copy of this message
In response to the other comments expressing surprise that changing the timezone does not affect the timestamp: A UNIX timestamp is defined as the number of seconds that have elapsed since 00:00:00 (UTC), Thursday, 1 January 1970. So: with respect to UTC. Always. Calling setTimezone() never changes the actual "absolute", underlying, moment-in-time itself. It only changes the timezone you wish to "view" that moment "from". Consider the following: <?php // A time in London. $datetime = new DateTime('2015-06-22T10:40:25', new DateTimeZone('Europe/London')); // I wonder how that SAME moment-in-time would // be described in other places around the world. $datetime->setTimezone(new DateTimeZone('Australia/Sydney')); print $datetime->format('Y-m-d H:i:s (e)'); // 2015-06-22 19:40:25 (Australia/Sydney) $datetime->setTimezone(new DateTimeZone('America/New_York')); print $datetime->format('Y-m-d H:i:s (e)'); // 2015-06-22 05:40:25 (America/New_York) $datetime->setTimezone(new DateTimeZone('Asia/Calcutta')); print $datetime->format('Y-m-d H:i:s (e)'); // 2015-06-22 15:10:25 (Asia/Calcutta) ?> Please note that ALL of these date strings unambiguously represent the exact same moment-in-time. Therefore, calling getTimestamp() at any stage will return the same result: <?php $datetime->getTimestamp(); // 1434966025 ?> ---- Server IP: 72.52.91.14 Probable Submitter: 205.223.239.158 ---- Manual Page -- http://php.net/manual/en/datetime.settimezone.php Edit -- https://master.php.net/note/edit/117514 Del: integrated -- https://master.php.net/note/delete/117514/integrated Del: useless -- https://master.php.net/note/delete/117514/useless Del: bad code -- https://master.php.net/note/delete/117514/bad+code Del: spam -- https://master.php.net/note/delete/117514/spam Del: non-english -- https://master.php.net/note/delete/117514/non-english Del: in docs -- https://master.php.net/note/delete/117514/in+docs Del: other reasons-- https://master.php.net/note/delete/117514 Reject -- https://master.php.net/note/reject/117514 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#202922) next »