Date.Parse()的时区问题

时间:2013-03-18 13:57:16

标签: javascript

我的脚本中有以下代码:

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

运行脚本后得到的结果是:

September 30, 2010 22:01:01

可能是Date.Parse()的问题还是我做错了什么?

1 个答案:

答案 0 :(得分:5)

这不是问题:它是feature

  

parse方法采用日期字符串(例如“Dec 25,1995”)并返回自1970年1月1日00:00: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.