Trabla: js: Date.getMonth() incorrect val
Example:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
var myDate = new Date();
myDate.setTime( Date.parse('2014-12-06 00:00:00') );
document.write(myDate.toString());
document.write('<br><br>Month:');
document.write(myDate.getMonth());
</script>
</body>
</html>
Solving:
getMonth() Returns the month (from 0-11)
So December is 11
http://www.w3schools.com/jsref/jsref_getmonth.asp
Fixed Example:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
var myDate = new Date();
myDate.setTime( Date.parse('2014-12-06 00:00:00') );
document.write(myDate.toString());
document.write('<br><br>Month:');
document.write(myDate.getMonth() + 1);
</script>
</body>
</html>
No comments:
Post a Comment