.now()
nikolaspoczekaj19 total contributions
Published Jul 22, 2021Updated Jun 2, 2023
Contribute to Docs
Returns the current time in milliseconds. The milliseconds count begins at 1970/01/01 at 00:00:00 UTC.
Syntax
Date.now();
Note: Since now()
is a static method of Date
, it will always be used as Date.now()
.
Example 1
Print the current date in milliseconds:
const time = Date.now();console.log(`The current date in milliseconds is ${time}.`);// Output: The current date in milliseconds is 1626374486136.// Note: your output may vary
Example 2
Calculate the number of months since 1970/01/01:
const time = Date.now();console.log(time);// Output: 1626367528657const minutes = 1000 * 60;const hours = minutes * 60;const days = hours * 24;const months = days * 30;const monthsSince1970 = Math.round(time / months);console.log(monthsSince1970);// Output: 627// Note: your output may vary
Codebyte Example
In this example, the function measures the time taken to execute a task. The code records the start time using Date.now()
before the task and again after the task is complete.
All contributors
- nikolaspoczekaj19 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- robgmerrill124 total contributions
- nikolaspoczekaj
- christian.dinh
- Anonymous contributor
- robgmerrill
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.