Parse JavaScript Date From String

Suppose you have a string representation of a date, e.g. “2015-05-15T22:43:35.0962104+02:00” or “5/15/2015”, and you need to parse that string into a JavaScript Date object. Here’s how to do it:

// Parse string into the number of milliseconds since January 1, 1970, 00:00:00 UTC.
var ticks = Date.parse("5/15/2015");

// Create an instance of Date using the number of milliseconds.
var date = new Date(ticks);

// Check the value of the Date instance 
console.log(date);
// yields "Mon Oct 05 2015 00:00:00 GMT+0200 (W. Europe Daylight Time)"

Freelance full-stack .NET and JS developer and architect. Located near Cologne, Germany.

Leave a Reply

Your email address will not be published. Required fields are marked *