Javascript - Date Input - Parsing Dates

Introduction

If you have a valid date string, you can use the Date.parse() method to convert it to Date object.

Date.parse() returns the number of milliseconds between the date and January 1, 1970:

Demo

var msec = Date.parse("March 21, 2012");
console.log(msec);/*from  w ww. ja v  a  2  s.  c o m*/

//You can then use the number of milliseconds to convert it to a date object:
//Date.parse(string) returns milliseconds.
//You can use the return value to convert the string to a date object:

var msec = Date.parse("March 21, 2012");
var d = new Date(msec);
console.log(d);

Result

Related Topic