note 103016 modified in book.datetime by danbrown
| From: | danbrown@php.net | Date: | Mon, 21 Mar 2011 20:51:11 +0000 |
| Subject: | note 103016 modified in book.datetime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178063@lists.php.net to get a copy of this message | ||
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"
?>
--was--
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://us2.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"
?>
http://php.net/manual/en/book.datetime.php