當我選擇@@ system_time_zone它給了我輸出作爲命名的時區,而不是小時:怎樣獲得MySQL服務器時區+/-小時
@@ system_time_zone
阿拉伯標準時間
我知道阿拉伯標準時間是+03:00,但我想輸出爲+03:00而不是命名的時區。
我可以向專家尋求幫助嗎?
當我選擇@@ system_time_zone它給了我輸出作爲命名的時區,而不是小時:怎樣獲得MySQL服務器時區+/-小時
@@ system_time_zone
阿拉伯標準時間
我知道阿拉伯標準時間是+03:00,但我想輸出爲+03:00而不是命名的時區。
我可以向專家尋求幫助嗎?
您可以在PhP中設置默認時區。因爲你可以創建一個新的日期對象,它給你在你設置的時區中的時間。
date_default_timezone_set("Europe/Berlin");
看看本作的更多信息:http://php.net/manual/de/function.date-default-timezone-get.php
這是爲您提供與預期結果的一個例子:
-- 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 |
+-----------+
我沒有downvote你,但我覺得你不應該依賴服務器時間,而是將時區信息存儲在'datetime'對象中。看看[這裏](http://stackoverflow.com/questions/2934258/how-do-i-get-the-current-time-zone-of-mysql)瞭解更多信息。 –