.getTime()
The .getTime()
method returns the number of milliseconds since the 1st of January 1970.
Syntax
myDate.getTime()
The returned value from .getTime()
is a value representing the number of milliseconds since the 1st of January 1970.
Example
In the example the variable myDate
stores the number of milliseconds from 1/1/1970 to the current time created using by the .getTime()
method on a new Date
and logs the result to the console.
const myDate = new Date('2023-01-01');console.log(myDate.getTime());
This will yield:
1672531200000
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.