JavaScript Date.now() method

1
184
javascript date now method
javascript date now method

What is Javascript Date.now() 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 now() method parses a date string and returns the number of milliseconds between the date string and midnight of January 1, 1970.

var millisecondsBetweenNowAnd1970 = Date.now();

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.

Then using the Date.now() method you can get milliseconds between present date-time and midnight of January 1, 1970.

Using this you can get, a persons age in milliseconds, from there the conversion to age in years, months, etc becomes super easy.

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.

SHARE
Previous articleJavaScript Date.parse() Method
Next articlePoll – Who will win the Cricket World Cup 2019 ?
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.

1 COMMENT

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.