Below is the example of Date now() method.
- Example:
<script>// Use of method Date.now()varA = Date.now();// Printing the number of millisecond elapseddocument.write("The time elapsed in millisecond is: "+ A);</script>chevron_rightfilter_none - Output:
The time elapsed in millisecond is: 1529644667834
The date.now() method is used to returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC. Since now() is a static method of Date, it will always be used as Date.now().
Syntax:
var A = Date.now();
Parameters: This method does not accepts any parameter.
Return Values: It returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
More codes for the above method are as follows:
Program 1: To get the current date, use the code below.
<script> // Use of Date.now() method var d = Date(Date.now()); // Converting the number of millisecond // in date string a = d.toString() // Printing the current date document.write("The current date is: " + a) </script> |
Output:
The current date is: Fri Jun 22 2018 10:54:33 GMT+0530 (India Standard Time)
Program 2: The Date(Date.now()) is same as Date(), so the same result can be achieved i.e, current date using the following code.
<script> // Using Date() method var d = Date(); // Converting the number value to string a = d.toString() // Printing the current date document.write("The current date is: " + a) </script> |
Output:
The current date is: Fri Jun 22 2018 11:02:01 GMT+0530 (India Standard Time)
Supported Browsers: The browsers supported by JavaScript Date now() method are listed below:
- Google Chrome
- Internet Explorer 9.0
- Mozilla Firefox
- Opera
- Safari
Recommended Posts:
- How to validate if input date (end date) in input field must be after a given date (start date) using express-validator ?
- How to validate if input date (start date) in input field must be before a given date (end date) using express-validator ?
- How to solve the issue that arise while using performance.now() method in javaScript?
- How to check the input date is equal to today's date or not using JavaScript ?
- How to convert UTC date time into local date time using JavaScript ?
- JQuery | now() method
- Lodash _.now() Method
- Underscore.js _.now() function
- D3.js now() function
- JavaScript Date toLocaleTimeString() Method
- JavaScript Date UTC() Method
- JavaScript Date getHours() Method
- JavaScript Date getMinutes() Method
- JavaScript Date getMonth() Method
- JavaScript Date getSeconds() Method
- JavaScript Date getDay() Method
- JavaScript Date getMilliseconds() Method
- JavaScript Date getFullYear() Method
- JavaScript Date getDate() Method
- JavaScript Date getUTCDate() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


