There is no second argument support for Date.parse
. Instead convert your input string to the ISO format by inserting the missing delimiters:
var dateToParse = "20191116T202021.000Z";
var test = Date.parse(dateToParse.replace(/(....)(..)(..T..)(..)/, "$1-$2-$3:$4:"));
console.log(test); // output as milliseconds
console.log(new Date(test).toJSON()); // output also in JSON format
As noted below, the above regular expression already does the work of parsing the string into its date parts, so you might as well pass those parts to Date.UTC
without building another string that needs parsing again. It just needs a little adjustment for the month number:
var dateToParse = "20191116T202021.000Z";
var parts = dateToParse.match(/(....)(..)(..)T(..)(..)(..)\.(...)Z/);
var test = Date.UTC(parts[1], parts[2]-1, parts[3], parts[4], parts[5], parts[6], parts[7]);
console.log(test); // output as milliseconds
console.log(new Date(test).toJSON()); // output also in JSON format
For more efficiency you would just slice the string into its fixed size pieces without the fancy regular expression:
var dateToParse = "20191116T202021.000Z";
var test = Date.UTC(dateToParse.slice(0,4),
dateToParse.slice(4,6)-1,
dateToParse.slice(6,8),
dateToParse.slice(9,11),
dateToParse.slice(11,13),
dateToParse.slice(13,15),
dateToParse.slice(16,19));
console.log(test); // output as milliseconds
console.log(new Date(test).toJSON()); // output also in JSON format