note 128842 added to class.datetimezone
| From: | JarmoTroska at main dot php dot net | Date: | Wed, 30 Aug 2023 09:15:37 +0000 |
| Subject: | note 128842 added to class.datetimezone | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220804@lists.php.net to get a copy of this message | ||
Example of converting between timezones using the DateTime and DateTimeZone classes.
Note that PHP will also take care of calculating relevant daylight savings!
<?php
$utc_timezone = new DateTimeZone("UTC");
$tallinn_timezone = new DateTimeZone("Europe/Tallinn");
// Create a new DateTime object in the UTC format
$datetime = new DateTime("2023-01-01 11:00:00", $utc_timezone);
// Convert the DateTime object to the timezone of Tallinn
$datetime->setTimezone($tallinn_timezone);
// Display the result in the YYYY-MM-DD HH:MM:SS format
echo $datetime->format('Y-m-d H:i:s');
// Returns: 2023-01-01 13:00:00
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 185.145.5.34)
----
Manual Page -- https://php.net/manual/en/class.datetimezone.php
Edit -- https://main.php.net/note/edit/128842
Del: integrated -- https://main.php.net/note/delete/128842/integrated
Del: useless -- https://main.php.net/note/delete/128842/useless
Del: bad code -- https://main.php.net/note/delete/128842/bad+code
Del: spam -- https://main.php.net/note/delete/128842/spam
Del: non-english -- https://main.php.net/note/delete/128842/non-english
Del: in docs -- https://main.php.net/note/delete/128842/in+docs
Del: other reasons-- https://main.php.net/note/delete/128842
Reject -- https://main.php.net/note/reject/128842
Search -- https://main.php.net/manage/user-notes.php