2
console.log(+new Date("2017-6-18"), +new Date("2017-06-18"));
//1497715200000 1497744000000

console.log(new Date("2017-6-18"), new Date("2017-06-18"));
//Sun Jun 18 2017 00:00:00 GMT+0800 (中国标准时间) Sun Jun 18 2017 08:00:00 GMT+0800 (中国标准时间)

The time "2017-6-18" and "2017-06-18" is same, but the timestamp of them is different

  • 3
    The behaviour of `new Date("2017-06-18")` is guaranteed by the JavaScript specification. `new Date("2017-6-18")` doesn’t follow the spec format and browsers can do anything with it (including interpreting it in a different timezone); don’t use it. – Ry- Jun 07 '17 at 02:59
  • 1
    Chrome treats those formats differently - firefox doesn't - so, as Ryan pointed out, use date formats that are in the spec, don't rely on how a browser may handle any "non-standard" format – Jaromanda X Jun 07 '17 at 03:00
  • Thank you!It just like “Follow the rules and make fewer mistakes” – 时间只会一直走 Jun 07 '17 at 03:02

0 Answers0