Converting UTC Dates to Local Time Zones in MySQL Select Queries
Question:
How can I modify a MySQL query to convert a UTC timestamp column, "displaytime," into the local time zone?
Answer 1:
Use the CONVERT_TZ() function as follows:
SELECT CONVERT_TZ(displaytime, 'GMT', 'MET');
Answer 2:
Ensure that your timezone tables are initialized. Use the mysql_tzinfo_to_sql program to populate them:
shell> mysql_tzinfo_to_sql /usr/share/zoneinfo
Once initialized, you can use the CONVERT_TZ() function as described above.
Additional Notes:
SELECT * FROM mysql.time_zone; SELECT * FROM mysql.time_zone_name;
以上是如何在 MySQL 選擇查詢中將 UTC 日期轉換為本機時區?的詳細內容。更多資訊請關注PHP中文網其他相關文章!