Date Input - Parsing Dates

If you have a valid date string, you can use the Date.parse() method to convert it to milliseconds. The Date.parse() method returns the number of milliseconds between the date and January 1, 1970. You can then use the number of milliseconds to convert it to a date object:

HTML file: Displayed by browser:
<body>
<h4>Convert a date to milliseconds:</h4>
<p id="demo"></p>
<h4>Convert the milliseconds to a date object:</h4>
<p id="demo2"></p>
<script>
var msec = Date.parse("March 21, 2012");
document.getElementById("demo").innerHTML = msec;
var msec = Date.parse("March 21, 2012");
var d = new Date(msec);
document.getElementById("demo2").innerHTML = d;
</script>
</body>

Convert a date to milliseconds:

Convert the milliseconds to a date object:

Ho, hum, getting so boring....

BackTable of ContentsNext