Reputation: 21
Just a quick question, how would I be able to edit the following Date/Time variable to PLUS(+) the hour number 5, at the moment it's in US time, I need to convert everything to UK time.
$tme = date('H:i : d F Y');
Any ideas...?
Upvotes: 1
Views: 125
Reputation: 175098
Use DateTime
objects, it's more robust and will give you less headaches:
$time = new DateTime("now", new DateTimeZone("America/New_York"));
$time->setTimezone(new DateTimeZone("Europe/London"));
echo $time->format("H:i:s Y-m-d");
Also note that with this, you can deal with weird timezone related oddities (such as some timezones changing in different dates, some are dependent of years etc) without doing any sort of computation, the DateTimeZone object does it for you :-)
Upvotes: 6
Reputation: 28929
Use DateTime
and DateTimeZone
instead:
// U.S. timezone (EST)
$tme = new DateTime('now', new DateTimeZone('America/New_York'));
echo $tme->format('H:i : d F Y');
// U.K. timezone
$tme->setTimeZone(new DateTimeZone('Europe/London'));
echo $tme->format('H:i : d F Y');
Upvotes: 0
Reputation: 16943
$tme = date('H:i : d F Y', time() + 60*5);
but you may be interested in DateTime object
or change timezone using
date_default_timezone_set('Europe/London');
Upvotes: 0
Reputation: 2288
Use date_default_timezone_set function
date_default_timezone_set('Europe/London');
Upvotes: 1
Reputation: 2895
Add this to the top of your page:
date_default_timezone_set('Europe/London');
Upvotes: 1