JavaScript | Date.now()
The Date.now() is an inbuilt function in JavaScript which 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();
Where A is time in millisecond.
Parameters: This function accepts no parameter.
Return Values: It returns the number of milliseconds elapsed since January 1, 1970, 00:00:00 UTC.
JavaScript code to show the working of Date.now() function:
Example 1:
<script> // Use of function Date.now() var A = Date.now(); // Printing the number of millisecond elapsed document.write("The time elapsed in millisecond is: " + A); </script> |
Output:
The time elapsed in millisecond is: 1529644667834
Example 2:
To get the current date, use the code below.
<script> // Use of Date.now() function 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)
Example 3:
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() function 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() Function are listed below:
- Google Chrome
- Internet Explorer 9.0
- Firefox
- Opera
- Safari
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
- JavaScript | Let
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.



