Forum Moderators: coopster

Message Too Old, No Replies

How to change GMT

         

asantos

1:42 am on Jan 22, 2009 (gmt 0)

10+ Year Member



Lets suppose it is 13h00 time o'clock on my server, which is on GMT-5.

If a user logs into my web app from England (GMT 0) he should not see 13h00, but he should see 18h00.

Is there a php flag i can activate in order to change the GMT setting for a specific user? (i already have a table with all countries and their GMT values).

coopster

2:09 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



There are a number of ways to accomplish this, one may be to use gmdate() to get the current timestamp which you would pass as the second argument to strtotime. In strtotime you would add/subtract the appropriate hours. See the PHP Date and Time Functions [php.net] for options.

asantos

7:05 pm on Jan 22, 2009 (gmt 0)

10+ Year Member



I came up with this solution:

1 -- $gmt['user'] = ###
where ### equals the GMT value of the country of the user (i have a country table with linked gmt values).

2 -- $time['gmt'] = time() - ($gmt['server'] * 60 * 60);
this takes the current time to greenwich time (GMT 0).
$gmt['server'] holds the value of the GMT of the webserver, in my case it is '-6' (Grand Central Time).

3 -- $time['user'] = $time['gmt'] + ($gmt['user'] * 60 * 60);
this takes the current greenwich time to the user GMT time.

So, at the end, $time['user'] holds the value i was searching for. BTW, if you need the time value of a record field calculated in the user's gmt, all you have to do is repllace the "time()" in step 2 with a specific timestamp value.

Opinions?