JavaScript Date.parse() Method

What is Javascript Date.parse() method used for ? Definition

Background: In Javascript, we have a Date Object, which has several methods available for us to use, Parse() method is just one of them.

The Date objects parse() method parses a date string and returns the number of milliseconds between the date string and midnight of January 1, 1970.

For example: In the example below, we pass a date string, which lets assume is your date of birth to the parse() method, and the method will return milliseconds between my DOB and midnight of January 1, 1970.

var DOB = “March 1, 1995”;
var millisecondsBetweenDOBAnd1970 = Date.parse(DOB);

Now the questions is What can this be used for ?

Javascript Data.parse() method Usage

Using the example, above we can easily understand where Date.parse() method can be used.

Usage Scenario:

You want to Calculate a persons age from their DOB

First Parse the Date of Birth, then use the method to get milliseconds between now (present date and time) and midnight of January 1, 1970.

Full tutorial & Video demo: Calculate age of a person using and Date.parse() method.

See the Pen Javascript to Calculate Age in Years, Months, Days when given a DOB by Navjot Singh Virk (@virksaabnavjot) on CodePen.

Click here for to see an example usecase of Date.parse() method

Default image
Navjot Singh Virk
Navjot is a Hobby Blogger from Ireland and loves to create content to help people. He makes time on weekends to work on this blog. And has a full time position at Verizon Media as Lead Technical Solutions Consultant, which he loves and thrives at. His Skills include in-depth knowledge of SEO, Javascript, Advertising, HTML and Java. And his other hobbies include Investing, Gardening and playing Table Tennis.