javascriptdate

Convert string to date in JavaScript


I have a string looking like so:

"2013/1/16"

Is there any way I could quickly convert it into date object in javascript, something like:

convertToDateTime("2013/1/16", "yyyy/MM/dd")

Solution

  • It's pretty simple:

    var myDate = new Date("2013/1/16");
    

    That should do the trick.
    Have a look at the documentation for the Date object