php - How to set time zones for different locations? -


i confused setting time zones. developing forum in php, in not sure displaying times replies.

below condition,

one question posted on 1 apr 2013 10.00 (time zone 'asia/calcutta'). replies on 31 mar 2013 11.30 pm because time zone of replied person 'america/chicago' -10.30 hours.

my question how manage time zones different locations?

in above example, should time displayed user has posted question , reply?

and should time displayed user replied question?

i using time function of php string insert time record in database. , display time used

date("d m y h:m a", strtotime($time)); 

above code $time value comes database.

thanks..

i store dates , times database using gmdate() make them gmt-based:

$d = gmdate('y-m-d h:i:s'); // store $d database 

when render page, take account user's timezone preference:

date_default_timezone_set('asia/singapore'); $ts = strtotime($date_from_db . ' gmt'); $date_on_page = date('y-m-d h:i:s', $ts); 

or let javascript handle time conversion.

update

you store unix timestamps in database; having datetime columns, because easier decode when you're trying debug :)


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -