Edit
Wow, completely missed the point of the question!
Seems you want dates from today going backwards for a set number of days in ISO 8601 format. The Date constructor will create a date, and Date.prototype.toISOString will return an ISO 8601 date. It just needs the time part trimmed.
So a function to returns date strings for all the dates from today going back n days is:
function getDateRange(n) {
var d = new Date(),
dates = [];
while (n--) {
dates.push(d.toISOString().split('T')[0]);
d.setDate(d.getDate() - 1);
}
return dates;
}
// Example
document.write(getDateRange(10).join('<br>'));
Original answer
The only reliable way to parse date strings in javascript is to do it manually. A library can help, but a bespoke function isn't much work:
function parseYMD(s) {
var b = s.split(/\D/);
return new Date(b[0], b[1]-1, b[2]);
}
document.write(parseYMD('2015-12-04'))
This assumes the string is a valid date and will parse the string to a local Date, consistent with ECMAScript 2015 (and ISO 8601). If you need to also validate the string, a couple of extra lines are required.