Created
August 31, 2012 14:02
-
-
Save rachellawson/3553071 to your computer and use it in GitHub Desktop.
Why doesn't this return a date in September??
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
var _date = new Date(); | |
_date.setMonth(8); | |
_date.setDate(10); | |
_date.setHours(9); | |
_date.setMinutes(00); | |
_date.setSeconds(00); | |
$('#daysuntil').append(_date.toString()); | |
}) | |
</script> | |
</head> | |
<body> | |
<div id="daysuntil"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah!!!!!
new Date() returns today's date by default and, as it was 31st August, then moving on to alter the month first meant that it was trying to make a date of 31st September, which doesn't exist.
js decided to instead go into October, then we change the day to 10 and that left us with the wrong date.