2013-03-18 88 views
0

我在我的腳本下面的一段代碼:時區問題與Date.Parse()

Date.parse('10/01/2010 01:01:01') 

結果運行該腳本後,我得到的是:

September 30, 2010 22:01:01 

是否可能Date.Parse()的問題還是我做錯了什麼?

+0

的日期_formatted_在您的本地時區,當您將它輸出。如果你不喜歡這樣,輸出另一種方式(你沒有說明你用什麼方式)。 – CBroe 2013-03-18 14:00:22

回答

5

這不是一個問題:這是一個feature

parse方法接受一個日期字符串(如「1995年12月25日」),並自00 1970年1月1日,返回的毫秒數: 00 UTC。本地時區用於解釋不包含時區信息的參數。 [...]如果您未指定時區,則假定爲本地時區。

...所以有之間的差異:

Date.parse("Thu, 01 Jan 1970 00:00:00"); 

// ... returns 14400000 in timezone GMT-0400, and other values in other 
// timezones, since there is no time zone specifier in the argument. 

......還有......

Date.parse("Thu, 01 Jan 1970 00:00:00 GMT-0400"); 
// ... returns 14400000 no matter the local time zone.