php - The standard way for switching from/to user_timezone and gmt -



php - The standard way for switching from/to user_timezone and gmt -

i utilize php's date_default_timezone_set() , set according user's timezone field in the user table. ease can show date/time users , date/time them.

but storing date related values in database, have utilize standard gmt timezone.

the question: what best or maybe standard way switching to/from user_timezone , gmt?

do suggest me follow these steps when want insert or update field in database?

change timezone using date_default_timezone_set('gmt'); get time using $inserttimestap = time(); or $inserttimestamp = mktime(); change timezone user default using: date_default_timezone_set($this->session->userdata('timezone'));

there absolutely no need utilize date_default_timezone_set('gmt') because converting gmt, there special set of functions function names begin 'gm':

gmmktime() gets timestamp in gmt timezone. gmdate() gives gmt date format.

there gmstrftime() php manual

furthermore it's notable time() returns current timestamp in gmt

php datetime timezone timestamp

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -