DS.Model 日期属性解析日期 (YYYY-MM-DD) 不正确 [英] DS.Model date attribute parses date (YYYY-MM-DD) incorrectly

查看:16
本文介绍了DS.Model 日期属性解析日期 (YYYY-MM-DD) 不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 DS.Model 解析日期格式为YYYY-MM-DD"时遇到问题.他们总是落后一天.

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

这是一个例子:

http://jsfiddle.net/ZUV8v/

在控制台上使用 Date 对象我得到了类似的结果

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)

这是 ember 错误还是 javascript 错误或 Chrome 错误,还是我遗漏了什么?

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

OSX 10.7 上的 Chrome 版本 21.0.1180.89

Chrome Version 21.0.1180.89 on OSX 10.7

推荐答案

我前几天遇到了这个问题.

I ran into this just the other day.

根据 ECMAScript 规范 15.9.1.15

According to the ECMAScript Specification 15.9.1.15

所有数字必须以 10 为基数.如果 MM 或 DD 字段不存在,则使用01"作为值.如果 HH、mm 或 ss 字段不存在,则使用00"作为值并且不存在的 sss 字段的值为000".不存在的时区偏移的值为Z".

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')

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

然后控制台输出本地时区的值.

The console then outputs the value in your local timezone.

这篇关于DS.Model 日期属性解析日期 (YYYY-MM-DD) 不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆