Parse Date From String In JavaScript

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)"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s