note 103016 deleted from book.datetime by peehaa
| From: | peehaa@php.net | Date: | Sun, 28 Apr 2019 10:33:06 +0000 |
| Subject: | note 103016 deleted from book.datetime by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210798@lists.php.net to get a copy of this message | ||
Note Submitter: rjstatic
----
A very verbose loop. The construct function for the DateTime class isn't working properly for
me but this works.
<?php
$date = "2011/03/20";
$date = explode("/", $date);
$time = "07:16:17";
$time = explode(":", $time);
$tz_string = "America/Los_Angeles"; // Use one from list of TZ names http://php.net/manual/en/timezones.php
$tz_object = new DateTimeZone($tz_string);
$datetime = new DateTime();
$datetime->setTimezone($tz_object);
$datetime->setDate($date[0], $date[1], $date[2]);
$datetime->setTime($time[0], $time[1], $time[2]);
print $datetime->format('Y/m/d H:i:s'); // Prints "2011/03/20 07:16:17"
?>