note 95834 modified in function.date by thiago
| From: | thiago@php.net | Date: | Mon, 25 Jan 2010 12:57:05 +0000 |
| Subject: | note 95834 modified in function.date by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165277@lists.php.net to get a copy of this message | ||
if you wish to output a local time, instead of using date_default_timezone_get() and
date_default_timezone_set() to manipulate your current timezone, simply create a new DateTime
object:
<?php
$timezone = new DateTimeZone( "Europe/London" );
$date = new DateTime();
$date->setTimezone( $timezone );
echo $date->format( 'H:i:s A / D, M jS, Y' );
?>
-> 22:59:34 PM / Sun, Jan 24th, 2010
Irrespective of current server location, this will output the local time in London, Europe.
No need to reset the server timezone back to the previous setting.
--was--
if you wish to output a local time, instead of using date_default_timezone_get() and
date_default_timezone_set() to manipulate your current timezone, simply create a new DateTime
object:
$timezone = new DateTimeZone( "Europe/London" );
$date = new DateTime();
$date->setTimezone( $timezone );
echo $date->format( 'H:i:s A / D, M jS, Y' );
-> 22:59:34 PM / Sun, Jan 24th, 2010
Irrespective of current server location, this will output the local time in London, Europe.
No need to reset the server timezone back to the previous setting.
http://php.net/manual/en/function.date.php