How can I parse fast a yyyy-mm-dd string (ie. "2010-10-14") into its year, month, and day numbers?
A function of the following form:
function parseDate(str) {
var y, m, d;
...
return {
year: y,
month: m,
day: d
}
}
You can split it:
The
+
operator forces it to be converted to an integer, and is immune to the infamous octal issue.Alternatively, you can use fixed portions of the strings:
You could take a look at the JavaScript split() method - lets you're split the string by the - character into an array. You could then easily take those values and turn it into an associative array..