Skip to content

Instantly share code, notes, and snippets.

@rachellawson
Created August 31, 2012 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rachellawson/3553071 to your computer and use it in GitHub Desktop.
Save rachellawson/3553071 to your computer and use it in GitHub Desktop.
Why doesn't this return a date in September??
<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>
@rachellawson
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment