一个诡异的日期问题,不知道有没有人踩过
发布于 4 年前 作者 AllenYao 4940 次浏览 来自 问答

image.png

image.png

是6.10版本的node 会是什么原因造成这种区别?

7 回复

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

A string value representing a date, specified in a format recognized by the Date.parse() method (these formats are IETF-compliant RFC 2822 timestamps and also strings in a version of ISO8601).
Note: Parsing of date strings with the Date constructor (and Date.parse(), which works the same way) is strongly discouraged due to browser differences and inconsistencies. Support for RFC 2822 format strings is by convention only. Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.

两种格式是不一样的,最好直接用 moment 或 date.js 等类库并显式指定格式。

因为返回值是 undefined , 以 50% 透明度作为区分 看错题了

var a = '2019-10-08’ var aa = new Date(a) Tue Oct 08 2019 08:00:00 GMT+0800 (中国标准时间)

var b = '2019-10-8’ var bb = new Date(b) Tue Oct 08 2019 00:00:00 GMT+0800 (中国标准时间)

时区有区别

遇到过类似的,这种格式2019-10-01的new Date之后得到的会是世界时 不要用这种就好了,比如这种2019/10/01得到的就是本地时区

图片.png 在node10上没有这个问题

很好奇这个,我换了6.10的几个版本,没试出来。。。

谢谢大家, 在西五区的服务器上跑出现这个问题的 国内的没这个问题

回到顶部