为什么Javascript'的日期()函数中断我的生日在Safari
Why does Javascript's Date() function break for my birthday in Safari?
在Safari中运行的Javascript与我的生日有关。对我来说,这有时会破坏表单的验证(因为表单用javascript输出检查输入,并且日期不再匹配)。我很想知道为什么会这样。
我的生日是1985年10月6日。在Javascript中,我使用:new Date(1985, 09, 06)
(注意月份是零索引的,但是日和年不是)
// My birthday
console.log("1985, 09, 06: " + new Date(1985, 09, 06))
// One day earlier/later
console.log("1985, 09, 07: " + new Date(1985, 09, 07))
console.log("1985, 09, 05: " + new Date(1985, 09, 05))
// One month earlier/later
console.log("1985, 10, 06: " + new Date(1985, 10, 06))
console.log("1985, 08, 06: " + new Date(1985, 08, 06))
// One year earlier/later
console.log("1986, 09, 06: " + new Date(1986, 09, 06))
console.log("1984, 09, 06: " + new Date(1984, 09, 06))
在Safari中运行此命令的结果如下:
// My birthday (note the day is wrong, and the time is 11pm)
Sat Oct 05 1985 23:00:00 GMT+1000 (AEST)
// One day earlier/later
Mon Oct 07 1985 00:00:00 GMT+1100 (AEDT)
Sat Oct 05 1985 00:00:00 GMT+1000 (AEST)
// One month earlier/later
Wed Nov 06 1985 00:00:00 GMT+1100 (AEDT)
Fri Sep 06 1985 00:00:00 GMT+1000 (AEST)
// One year earlier/later
Mon Oct 06 1986 00:00:00 GMT+1100 (AEDT)
Sat Oct 06 1984 00:00:00 GMT+1000 (AEST)
https://jsfiddle.net/27bupLr9/在Chrome中,我的生日是正确创建的:
console.log(new Date(1985, 09, 06))
Sun Oct 06 1985 00:00:00 GMT+1000 (AEST)
此问题已在macOS High Sierra中解决。
相关文章:
- 递归函数中断
- 从jquery foreach内部中断函数
- JavaScript 函数在 IE9 中随机中断
- Angularjs 与 coffeescript 函数表达式中断
- Javascript:变量中断函数
- return语句在JavaScript中使用而不中断函数
- 调用加载的顺序函数会意外中断代码
- 从匿名函数中中断for循环
- 清除文本区域会中断其他JS函数
- 如何在返回值(Js)时不中断函数/循环
- 进度条函数在一次调用后中断
- 一个函数在另一个函数上中断.可能吗
- 中断 JQuery 设置超时函数
- 在 ASP.NET 页面中内联编码 SVG 会导致 SVG JavaScript 创建 SVGPoint();函数中断
- 从调用/子函数退出/中断主函数
- 在事件上中断函数
- 如果条件不通过,则中断函数
- Javascript:将变量传递给函数会中断函数
- atom美化插件中断函数参数
- 使用getTime的停止/中断函数执行