您正在使用包含「Dplaytime」列的Mydisplaytime」欄位的MycSQL 查詢以UTCUTCUTC格式儲存時間戳記。但是,您需要顯示本地時區的時間戳記。 CONVERT_TZ() 函數未如預期般運作。
要使用 CONVERT_TZ() 函數將 UTC 時間戳轉換為本地時區,您必須指定兩者的時區縮寫UTC 和本地時區。正確的語法如下:
SELECT CONVERT_TZ(displaytime, 'UTC', 'LOCAL')
範例查詢
WHERE displaytime >= '2012-12-01 00:00:00' AND displaytime <= '2013-02-22 23:59:59' AND ct.organizationId IN ( SELECT t.organizationId FROM organization_ AS t JOIN organization_ AS p ON t.treePath LIKE CONCAT(p.treePath, '%') WHERE p.organizationId = 10707 )
修改後的查詢:
WHERE CONVERT_TZ(displaytime, 'UTC', 'LOCAL') >= '2012-12-01 00:00:00' AND CONVERT_TZ(displaytime, 'UTC', 'LOCAL') <= '2013-02-22 23:59:59' AND ct.organizationId IN ( SELECT t.organizationId FROM organization_ AS t JOIN organization_ AS p ON t.treePath LIKE CONCAT(p.treePath, '%') WHERE p.organizationId = 10707 )
以上是如何在 MySQL 選擇查詢中將 UTC 日期轉換為本機時區?的詳細內容。更多資訊請關注PHP中文網其他相關文章!