新的Date()一天日期时间字符串在JavaScript中返回前一天

编程入门 行业动态 更新时间:2024-10-12 22:25:53
本文介绍了新的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中返回前一天

本文发布于:2023-11-24 02:29:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623640.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   日期   时间   Date   JavaScript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!