note 104111 added to datetime.construct
| From: | joel dot kallman at gmail dot com | Date: | Tue, 24 May 2011 01:14:09 +0000 |
| Subject: | note 104111 added to datetime.construct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179992@lists.php.net to get a copy of this message | ||
A definite "gotcha" (while documented) that exists in the __construct is that it ignores
your timezone if the $time is a timestamp. While this may not make sense, the object does provide
you with methods to work around it.
// New Timezone Object
$timezone = new DateTimeZone('America/New_York');
// New DateTime Object
$date = new DateTime('@1306123200', $timezone);
// You would expect the date to be 2011-05-23 00:00:00
// But it actually outputs 2011-05-23 04:00:00
echo $date->format('Y-m-d H:i:s');
// You can still set the timezone though like so...
$date->setTimezone($timezone);
// This will now output 2011-05-23 00:00:00
echo $date->format('Y-m-d H:i:s');
----
Server IP: 69.147.83.197
Probable Submitter: 174.55.38.37
----
Manual Page -- http://www.php.net/manual/en/datetime.construct.php
Edit -- https://master.php.net/note/edit/104111
Del: integrated -- https://master.php.net/note/delete/104111/integrated
Del: useless -- https://master.php.net/note/delete/104111/useless
Del: bad code -- https://master.php.net/note/delete/104111/bad+code
Del: spam -- https://master.php.net/note/delete/104111/spam
Del: non-english -- https://master.php.net/note/delete/104111/non-english
Del: in docs -- https://master.php.net/note/delete/104111/in+docs
Del: other reasons-- https://master.php.net/note/delete/104111
Reject -- https://master.php.net/note/reject/104111
Search -- https://master.php.net/manage/user-notes.php