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 usingdate_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
Post a Comment