I have a string representing the current time: 2015-11-24T19:40:00
. How do I parse this string in Javascript to get a Date represented by this string as the
A variation on RobG's terrific answer.
Note that this will require that you run bleeding edge JavaScript as it relies on the arrow notation and spread operator.
function parseDateISOString(s) {
let ds = s.split(/\D+/).map(s => parseInt(s));
ds[1] = ds[1] - 1; // adjust month
return new Date(...ds);
}
The benefit of this approach is that it automatically applies the correct number of arguments passed. If this is what you want.