Jump to content

Converting time to users localtime


Clarkeez

Recommended Posts

Do you know the timezone for the user? If so, converting a time to another timezone is a simple task. Ideally, I would store the time from GMT, but even if you have it stored in a different timezone you can still convert from that to another. But, the real question is whether you have captured the timezone for the user, such as having them select their timezone when they create an account. If you have not provided a means for the user to select their timezone, there are ways to auto-detect it via JavaScript, but I'm not sure how foolproof that is.

Thanks guys, I suppose I should get their timezone with the registration form.

 

Erm, so once I have that, how would i actually do it..

 

something like, for example..

 

mysql_connect blah blah

$q = mysql_query("SELECT p.time_posted AS time_posted, u.timezone AS timezone FROM post.p LEFT OUTER JOIN user u ON u.id = p.poster WHERE p.id = 'whatever'"); // time_posted field type is datetime

$d = mysql_fetch_array($q);

 

$localtime = idontknowthisbit_somefunction?($d['time_posted'], $d['timezone']);

echo $localtime;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.