DS.Model date attribute parses date (YYYY-MM-DD) incorrectly

跟風遠走 提交于 2019-12-19 14:53:19

问题


I am having a issue with my DS.Model parsing dates in the format of "YYYY-MM-DD". They are always one day behind.

Here is an example:

http://jsfiddle.net/ZUV8v/

Using Date objects on the console I get similar results

> new Date('2012-09-20')
Wed Sep 19 2012 17:00:00 GMT-0700 (PDT)

Is this a ember bug or a javascript bug or a Chrome bug or am I missing something?

Chrome Version 21.0.1180.89 on OSX 10.7


回答1:


I ran into this just the other day.

According to the ECMAScript Specification 15.9.1.15

All numbers must be base 10. If the MM or DD fields are absent "01" is used as the value. If the HH, mm, or ss fields are absent "00" is used as the value and the value of an absent sss field is "000". The value of an absent time zone offset is "Z".

new Date('2012-09-20')

is the same as

new Date("2012-09-20T00:00:00.000Z")

The console then outputs the value in your local timezone.



来源:https://stackoverflow.com/questions/12523373/ds-model-date-attribute-parses-date-yyyy-mm-dd-incorrectly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!