Why does Javascript's Date() function break for my birthday in Safari?

Andy

Javascript running in Safari has a problem with my birthday. This sometimes breaks validation in forms for me (as forms check the input with the javascript output, and the days don't match anymore). I'd love to know why this happens.

My birthday is 6th Oct 1985. In Javascript, I create this using:

new Date(1985, 09, 06)

(Note that months are zero-indexed, but days and years are not.)

// 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))

Results running this in Safari are:

// 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/

In Chrome, my birthday is created correctly:

console.log(new Date(1985, 09, 06))
Sun Oct 06 1985 00:00:00 GMT+1000 (AEST)
Andy

This has been resolved in macOS High Sierra.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does my Javascript trim Function not work?

From Dev

Why does my Netbeans debugger break into a commented line of code?

From Dev

Why does `log_slow_queries` break `my.cnf`?

From Dev

Why does this function break in Powershell?

From Dev

Why does my setInterval function not work second time? (JavaScript)

From Dev

why do spaces break my code in javascript?

From Dev

MongoDB Java client - why does `sort` seem to break my query?

From Dev

Why does the compiler insist my function is inline when it's not?

From Dev

Why does adding a show/hide feature break my AngularJS code?

From Dev

Why does calling focus() break my CSS transition?

From Dev

why does RewriteCond %{SCRIPT_FILENAME} !-d break my RewriteRule

From Dev

Why does cloning a repo break my yii2 app?

From Dev

Why does my Javascript break in IE8?

From Dev

Why does having the time in GNU date break "- 1 day"?

From Dev

Why does inlining my accessors break my code?

From Dev

why firefox does not break the date?

From Dev

Why does adding a super-class break my Spring beans?

From Dev

Why is Javascript Changing My Date?

From Dev

Why does uint break my for loop?

From Dev

Why does jQuery selectable break this click function?

From Dev

Why Does JavaScript Automatically Allow My Function To Take An Extra Argument?

From Dev

Why does my dynamic javascript highlight form break?

From Dev

Why does calling this Javascript function submit my form?

From Dev

Why does Javascript's Date() function break for my birthday in Safari?

From Dev

Why does my function not run?

From Dev

Why does my edit/update route break?

From Dev

Why does the javascript's .toUpperCase function include numbers?

From Dev

In JavaScript, why does this global variable become undefined in my function?

From Dev

Why does JavaScript add 5 hours to my date?

Related Related

  1. 1

    Why does my Javascript trim Function not work?

  2. 2

    Why does my Netbeans debugger break into a commented line of code?

  3. 3

    Why does `log_slow_queries` break `my.cnf`?

  4. 4

    Why does this function break in Powershell?

  5. 5

    Why does my setInterval function not work second time? (JavaScript)

  6. 6

    why do spaces break my code in javascript?

  7. 7

    MongoDB Java client - why does `sort` seem to break my query?

  8. 8

    Why does the compiler insist my function is inline when it's not?

  9. 9

    Why does adding a show/hide feature break my AngularJS code?

  10. 10

    Why does calling focus() break my CSS transition?

  11. 11

    why does RewriteCond %{SCRIPT_FILENAME} !-d break my RewriteRule

  12. 12

    Why does cloning a repo break my yii2 app?

  13. 13

    Why does my Javascript break in IE8?

  14. 14

    Why does having the time in GNU date break "- 1 day"?

  15. 15

    Why does inlining my accessors break my code?

  16. 16

    why firefox does not break the date?

  17. 17

    Why does adding a super-class break my Spring beans?

  18. 18

    Why is Javascript Changing My Date?

  19. 19

    Why does uint break my for loop?

  20. 20

    Why does jQuery selectable break this click function?

  21. 21

    Why Does JavaScript Automatically Allow My Function To Take An Extra Argument?

  22. 22

    Why does my dynamic javascript highlight form break?

  23. 23

    Why does calling this Javascript function submit my form?

  24. 24

    Why does Javascript's Date() function break for my birthday in Safari?

  25. 25

    Why does my function not run?

  26. 26

    Why does my edit/update route break?

  27. 27

    Why does the javascript's .toUpperCase function include numbers?

  28. 28

    In JavaScript, why does this global variable become undefined in my function?

  29. 29

    Why does JavaScript add 5 hours to my date?

HotTag

Archive