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 Date.now() 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 Date.now() 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 a detailed example and video tutorial that explains this well.

SHARE
Previous articlePassion 4 Food Review, Clanbrassil Street, Dublin
Next articleJavaScript Date.now() method
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 Technical Solutions Consultant, which he loves and thrives at. His Skills include in-depth knowledge of SEO, Javascript, Advertising, HTML and Java.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.