Possible Duplicate:
Zero-based month numbering
The explanation in the book I am reading says, "Well, my Aunt starts counting her months from 1 like everyone else, so we subtract 1.
Here's the input string date: "died 27/04/2006: Black Leclère"
Here's the code:
function extractDate(paragraph) {
function numberAt(start, length) {
return Number(paragraph.slice(start, start + length));
}
return new Date(numberAt(11, 4), numberAt(8, 2) - 1,
numberAt(5, 2));
}
alert(extractDate("died 27-04-2006: Black Leclère"));
04 - 1 is 03. But here's the output date object: Thu Apr 27 2006 00:00:00
.
Knowing what we want for the output doesn't explain the unusual behavior of the language and the subsequent necessity of the -1. Please, explain.