开发者

How to save time as UTC time in php/mysql?

开发者 https://www.devze.com 2022-12-15 09:03 出处:网络
I use date_default_timezone_set($_SESSION[\'time_zone\']); to set a users timezone on a page, I am wanting to know, how do I save current time to mysql in php with the current UTC date and time?Al

I use

date_default_timezone_set($_SESSION['time_zone']); 

to set a users timezone on a page, I am wanting to know, how do I save current time to mysql in php with the current UTC date and time? Also should I be storing it as a timestamp?

My existing site used datetime fields and when I sav开发者_开发百科ed a new item to mysql I could just use now() in the php part making the insert or update query


Here are the relevant MySQL functions if you'd rather do it in your SQL:

SELECT UTC_TIMESTAMP(), UTC_DATE(), UTC_TIME();

UTC_TIMESTAMP() is what you're looking for if you want to store as a DATETIME field


gmdate('U'); outputs the GMT/UTC timestamp of the specified timestamp based on the current timezone.

See more information on the PHP Manual page

0

精彩评论

暂无评论...
验证码 换一张
取 消