note 113532 added to datetime.modify
| From: | php at lanar dot com dot au | Date: | Sat, 26 Oct 2013 06:50:23 +0000 |
| Subject: | note 113532 added to datetime.modify | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197325@lists.php.net to get a copy of this message | ||
modify() ignores any timezone information in the data while the DateTime constructor does not.
$dt = new DateTime( '2013-10-26T11:00:00+11:00' )
will create a +11 timezone while
$dt->modify( '2013-10-26T11:00:00+02:00' )
does not change the timezone or the time.
<?php
$dt = new DateTime( '2013-10-26T15:00:00Australia/Melbourne' ) ;
echo "\n", $dt->format( "c" ) ;
echo "\nTimezone '", $dt->getTimezone()->getName() . "'." ;
// modify $dt to 1 am new york which is 3 pm melbourne
$dt->modify( '2013-10-26T01:00:00America/New_York' ) ;
// result is 1 am melbourne time, not 3 pm
echo "\n", $dt->format( "c" ) ;
echo "\nTimezone '", $dt->getTimezone()->getName() . "'." ;
?>
Output
2013-10-26T15:00:00+11:00
Timezone 'Australia/Melbourne'.
2013-10-26T01:00:00+11:00
Timezone 'Australia/Melbourne'.
----
Server IP: 192.41.45.150
Probable Submitter: 114.76.128.172
----
Manual Page -- http://php.net/manual/en/datetime.modify.php
Edit -- https://master.php.net/note/edit/113532
Del: integrated -- https://master.php.net/note/delete/113532/integrated
Del: useless -- https://master.php.net/note/delete/113532/useless
Del: bad code -- https://master.php.net/note/delete/113532/bad+code
Del: spam -- https://master.php.net/note/delete/113532/spam
Del: non-english -- https://master.php.net/note/delete/113532/non-english
Del: in docs -- https://master.php.net/note/delete/113532/in+docs
Del: other reasons-- https://master.php.net/note/delete/113532
Reject -- https://master.php.net/note/reject/113532
Search -- https://master.php.net/manage/user-notes.php