.getTime()
Published Jun 10, 2023Updated Jan 17, 2024
Contribute to Docs
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
Codebyte Example
Below is a runnable codebyte which defines today
as today’s date and then converts it into milliseconds by using the .getTime()
method. A console.log()
then prints the value:
Contribute to Docs
- 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.