2016-09-25 69 views
-1

當我選擇@@ system_time_zone它給了我輸出作爲命名的時區,而不是小時:怎樣獲得MySQL服務器時區+/-小時

@@ system_time_zone
阿拉伯標準時間

我知道阿拉伯標準時間是+03:00,但我想輸出爲+03:00而不是命名的時區。

我可以向專家尋求幫助嗎?

+0

我沒有downvote你,但我覺得你不應該依賴服務器時間,而是將時區信息存儲在'datetime'對象中。看看[這裏](http://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql)瞭解更多信息。 –

回答

0

這是爲您提供與預期結果的一個例子:

-- set some time zone 
set @@session.time_zone='Asia/Kolkata'; 
select concat(concat(if(timestampdiff(hour, utc_timestamp,current_timestamp)>0,'+',''), 
timestampdiff(hour, utc_timestamp, current_timestamp)), 
':', 
MOD(timestampdiff(minute, utc_timestamp, current_timestamp), 60)) as zone_diff from dual; 


+-----------+ 
| zone_diff | 
+-----------+ 
| +5:30  | 
+-----------+