How can you get an array of dates from a string in the simplest way possible? For example, from ['15.02.2016','16.02.2016','17.02.2016']
to make ['15.02.2016','16.02.2016','17.02.2016']
|
1 answer
function fn(str) { str = str.split(/-|\./); var arr = [], from = new Date(str[2], str[1] - 1, str[0]), to = new Date(str[5], str[4] - 1, str[3]); for (; from <= to;) { arr.push((from.getDate() + "." + (from.getMonth() + 1) + "." + from.getFullYear()).replace(/(^|\.)(?=\d\.)/g, "$10")); from.setDate(from.getDate() + 1); } return arr; } document.write(JSON.stringify(fn('15.02.2016-17.02.2016')));
|
-
, translation of lines into dates and the usual cycle - Grundy