How to create a date object from string in javascript

Bader picture Bader · Nov 22, 2011 · Viewed 362.2k times · Source

Having this string 30/11/2011. I want to convert it to date object.

Do I need to use :

Date d = new Date(2011,11,30);   /* months 1..12? */

or

Date d = new Date(2011,10,30);   /* months 0..11? */

?

Answer

Dogbert picture Dogbert · Nov 22, 2011
var d = new Date(2011,10,30);

as months are indexed from 0 in js.