tags:

views:

25

answers:

2

Hello,

I store all datetime values as unix timestamp. Registered users can set personal GMT locale in their profile. What should I do to display all datetime on website in user's GMT locale?

Thank you

+1  A: 

There's no such thing as "user's GMT locale". You must be referring to the user's timezone.

You can convert unix timestamps to dates in the user timezone this way:

$timestamp = ...;
$tz = new DateTimezone("Europe/Lisbon"); //substitute by the user's timezone
$d = new DateTime("@$timestamp");
$d->setTimezone($d);
echo $d->format(DateTime::RFC822);

If you only have a GMT offset, you can use:

$tz = new DateTimezone("Etc/GMT-12");

Note, however, that if you use GMT offsets, you will have to change them when the users enter or leave daylight saving time.

Artefacto
A: 

With PHP:

date("Y-m-d H:i:s", $timestamp);

With MySQL:

FROM_UNIXTIME()
Amirouche Douda
In the user locale, not in the server's.
prodigitalson
Ok, in that case, I see now Artefacto answered the question. I add just the List of Supported Timezones http://ch2.php.net/manual/en/timezones.php
Amirouche Douda