Hawiak
Hawiak

Reputation: 553

Timezone conversion, how do I do this the best and correctly

So I have the following

Now what do I want?

I want to display the time for the user in his timezone so if the match is on 12:00 in GMT+0 (Europe/London) then I want it to be displayed as 13:00 for Europe/Amsterdam.

I have no idea how to do this, please help me out ;)

EDIT Sorry, I use PHP

Upvotes: 1

Views: 62

Answers (1)

Sherif
Sherif

Reputation: 11942

You can use PHP's DateTime class, which does a wonderful job of handling date/times and timezones. Here's an example of what you want.

/* Create a DateTime object using Europe/London Timezone */
$date = new DateTime("2012-12-10 12:00", new DateTimeZone("Europe/London"));
echo $date->format('r'); // Mon, 10 Dec 2012 12:00:00 +0000

/* Change the timezone to Europe/Amsterdam and output the new formatted date/time */
$date->setTimezone(new DateTimeZone("Europe/Amsterdam"));
echo $date->format('r'); // Mon, 10 Dec 2012 13:00:00 +0100

Upvotes: 5

Related Questions