Abhay Abhay - 1 year ago 203
Javascript Question

Convert the format yyyy-MM-ddTHH:mm:ss to datetime in javascript which is acceptable by getTime() function

I have a date in the format yyyy-MM-ddTHH:mm:ss and I want to convert it to datetime format in such a way that if the result is evaluated via getTime() method, it will return number of milliseconds. For now, the method I have tried is throwing the error : Uncaught TypeError: dt.getTime is not a function where dt is the resultant date. Please state a way to achieve this using javascript.

Thanks in advance.

Answer Source

If your date is string, you should initialize new Date object with your time string as parameter. getTime() is method of Date object. Note that it may not work in all browsers.

var date = new Date('2016-11-09T18:00:01');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download