新的Date()一天日期时间字符串在JavaScript中返回前一天 [英] new Date() return a day before the day in date time string in javascript

查看:139
本文介绍了新的Date()一天日期时间字符串在JavaScript中返回前一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来代替已有的日期时间字符串

I have an existing date time string in place

new Date('2014-08-01T00:00:00')

但不是返回2014-08-01,它返回在实际angularJS视图2014年7月31日。

But instead of returning 2014-08-01, it returns as 2014-07-31 in the actually angularJS view.

我奇怪的是这个日期时间字符串有效的,如果没有,为什么它不是有效的。

I wonder is this date time string valid, if not, why its not valid.

能否 T 是字符串返回一个错误的日期的原因是什么?

Could the T be the reason that the string return a wrong date?

在返回的console.log 周四2014年7月31日20:00:00 GMT-0400(EDT)的日期

The console.log return a date of Thu Jul 31 2014 20:00:00 GMT-0400 (EDT)

感谢您

让我们调用这些-2是有毒的投票起伏。他们真的应该记得的日子时,他们都在努力理解基本概念,现在apparant给他们。它是一种耻辱。

推荐答案

在present(秋季2014年),JavaScript的日期/时间格式的ISO-8601发散的一个非常重要的方式:如果没有时区的上字符串,它假定以Z (祖鲁,GMT)。

At present (Autumn 2014), JavaScript's date/time format diverges from ISO-8601 in a very important way: If there's no timezone indicator on the string, it assumes Z ("Zulu", GMT).

所以

new Date('2014-08-01T00:00:00')

...是午夜北京时间8月1日。如果你住GMT以东,那将是在您的本地时间31日。

...is August 1st at midnight GMT. If you live east of GMT, that will be on the 31st in your local time.

然而,这个不兼容的ISO-8601被固定在ES6和某些实现(包括Chrome浏览器最新的V8)已经更新了。该ES6规格更改默认为本地时间;在的 PDF文件草案这个非官方的HTML版本

However, this incompatibility with ISO-8601 is being fixed in ES6 and some implementations (including the latest V8 in Chrome) are already updating it. The ES6 spec changes the default to local time; check out §20.3.1.15 ("Date Time String Format", the section number may change) in the draft PDFs or this unofficial HTML version.

这篇关于新的Date()一天日期时间字符串在JavaScript中返回前一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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