How do I change MySQL timezone?
更新時(shí)間:2008年03月26日 22:09:39 作者:
The MySQL timezone is set to MST (-7 hours GMT/UTC) and is not configurable by you. MySQL is only capable of having 1 timezone setting per mysql daemon. Therefore, you cannot select NOW() and expect a result in a timezone other than MST.
However, there are ways for you to get results that are in your preferred timezone. First determine how many hours your desired timezone is off from MST. For example, EST is +2 hours. PST is -1 hour.
Knowing the time offset, you can replace all your SQL statements of
SELECT NOW();
with
SELECT DATE_ADD(NOW(), INTERVAL 2 HOUR);
which will give you an EST date result. For a result in PST, you would do:
SELECT DATE_SUB(NOW(), INTERVAL 1 HOUR);
If you are working with time in seconds instead of dates, then factor in the offset in seconds. Because there are 3600 seconds in an hour, and EST is 2 hours later than MST, the following converts timestamps from MST to EST:
SELECT unix_timestamp() + (3600 * 2);
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP() + (3600 * 2));
See the MySQL Manual's Date and Time Functions for more information.
Depending on your application, you may also need to do one of the following (but not both):
1. Find every place in your code where a date or time is displayed to the browser and have a user defined function change it to add or subtract the appropriate number of hours before displaying it.
2. Find every place in your code where dates or times are input into your system and have a user defined function add or subtract the appropriate number of hours before storing it.
相關(guān)文章
php基于curl實(shí)現(xiàn)的股票信息查詢類實(shí)例
這篇文章主要介紹了php基于curl實(shí)現(xiàn)的股票信息查詢類,結(jié)合完整實(shí)例形式分析了php使用curl調(diào)用API接口實(shí)現(xiàn)股票信息查詢功能的相關(guān)操作技巧,需要的朋友可以參考下2016-11-11
基于PHP實(shí)現(xiàn)解密或加密Cloudflar郵箱保護(hù)
這篇文章主要介紹了基于PHP實(shí)現(xiàn)解密Cloudflar郵箱保護(hù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
利用php+mcDropdown實(shí)現(xiàn)文件路徑可在下拉框選擇
以下是對(duì)php+mcDropdown實(shí)現(xiàn)文件路徑可在下拉框進(jìn)行選擇的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下2013-08-08
php+js實(shí)現(xiàn)的拖動(dòng)滑塊驗(yàn)證碼驗(yàn)證表單操作示例【附源碼下載】
這篇文章主要介紹了php+js實(shí)現(xiàn)的拖動(dòng)滑塊驗(yàn)證碼驗(yàn)證表單操作,結(jié)合實(shí)例形式分析了php+js拖動(dòng)滑塊驗(yàn)證碼驗(yàn)證表單操作基本功能實(shí)現(xiàn)與使用相關(guān)操作技巧,需要的朋友可以參考下2020-05-05
PHP+FLASH實(shí)現(xiàn)上傳文件進(jìn)度條相關(guān)文件 下載
PHP+FLASH實(shí)現(xiàn)上傳文件進(jìn)度條相關(guān)文件 下載...2007-07-07

