I'm attempting to convert a Date String to a unix timestamp in Node.js.
My code below works perfectly on my client but when I run it on my server I get an error:
(node:19260) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: input.substring is not a function
My code:
function dateParser(input) {
// function is passed a date and parses it to create a unix timestamp
// removing the '.000' from input
let finalDate = input.substring(0, input.length - 4);
return new Date(finalDate.split(' ').join('T')).getTime();
}
Example of my input would be 2017-09-15 00:00:00.000
So why does the above work on my client but not in Node, and how would I duplicate the functionality in node?
dateParser()being called and what is being passed to it?console.log(typeof input)?Date.parse()to get the Unix timestamp representation of the date.