2013-08-27 59 views
0

我有一個SQL腳本運行在linux上從一個PHP文件,總是返回時間爲2小時超前我們。 Linux盒子在本地運行,當我在shell中執行「日期」時,它會返回正確的時間。任何想法爲什麼我一個人提前2小時退回CURTIME?CURTIME無論如何返回2小時無論如何

即使我跑

echo date('Y-m-d H:i:s'); 
echo date('Y-m-d H:i:s', mktime()); 

echo exec('date'); 

都呼應了正確的時間這對我來說,現在是

2013年8月27日12時44分52秒

2013年8月27日12 :44:52

星期二8月27日12點44分52秒PDT 2013

但無論我做什麼它插入成14時44分52秒

+2

什麼是你的php默認的時區設置? –

+0

據推測,這是UTC的時間(http://en.wikipedia.org/wiki/Coordinated_Universal_Time)。 –

+0

date_default_timezone_set('America/Los_Angeles'); –

回答

1

MySQL數據庫從MySQL:

值在當前時區表示。

如果你想讓它在你的時區顯示,你需要將其轉換成你想要做這樣的事情Documentation相應的時區:

select convert_tz(now(), @@global.time_zone, '-5:00'); 
select date(convert_tz(now(), @@global.time_zone, '-5:00')); 
select time(convert_tz(now(), @@global.time_zone, '-5:00')); 

# The second value gets the time of the server so it knows what to convert from. 

# The third value is your timezone you want to display 
# It can either be an offset, or name (if table is installed): 
# 'UTC', 'PST', 'MET', and so on