I am trying to convert a string format of date into a date object in JavaScript. I am getting different kinds of date formats like "dd/MM/yyyy HH:mm:ss" or "dd-MM-yyyy HH:mm:ss" or "MM-dd-yyyy HH:mm:ss" etc. I want to convert them into timestamp and display them in UI. I tried below code for getting date object
new Date("05/01/2012 21:10:17");
Tue May 01 2012 21:10:17 GMT+0530 (India Standard Time)
new Date("15/01/2012 21:10:17");
Invalid Date
new Date("15-01-2012 21:10:17");
Invalid Date
new Date("05-01-2012 21:10:17");
Tue May 01 2012 21:10:17 GMT+0530 (India Standard Time)
Few of them are getting Invalid Date
. Please help me, is there any specific code/logic to convert any string format to date object?