首頁 php教程 php手册 How do I change MySQL timezone?

How do I change MySQL timezone?

Jun 13, 2016 pm 12:30 PM
change mysql



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.

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

PHP 的大數據結構處理技巧 PHP 的大數據結構處理技巧 May 08, 2024 am 10:24 AM

PHP 的大數據結構處理技巧

如何優化 PHP 中的 MySQL 查詢效能? 如何優化 PHP 中的 MySQL 查詢效能? Jun 03, 2024 pm 08:11 PM

如何優化 PHP 中的 MySQL 查詢效能?

如何在 PHP 中使用 MySQL 備份和還原? 如何在 PHP 中使用 MySQL 備份和還原? Jun 03, 2024 pm 12:19 PM

如何在 PHP 中使用 MySQL 備份和還原?

Java 枚舉類型在資料庫中的應用場景有哪些? Java 枚舉類型在資料庫中的應用場景有哪些? May 05, 2024 am 09:06 AM

Java 枚舉類型在資料庫中的應用場景有哪些?

如何使用 PHP 插入資料到 MySQL 表? 如何使用 PHP 插入資料到 MySQL 表? Jun 02, 2024 pm 02:26 PM

如何使用 PHP 插入資料到 MySQL 表?

如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤 如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤 Dec 09, 2024 am 11:42 AM

如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤

如何在 PHP 中使用 MySQL 預存程序? 如何在 PHP 中使用 MySQL 預存程序? Jun 02, 2024 pm 02:13 PM

如何在 PHP 中使用 MySQL 預存程序?

PHP數組分頁的效能最佳化策略 PHP數組分頁的效能最佳化策略 May 02, 2024 am 09:27 AM

PHP數組分頁的效能最佳化策略

See all articles