Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jun 21, 2023
Contribute to Docs

The .setTime() method sets the date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970.



The returned value from .setTime() is a value representing the number of milliseconds since the 1st of January 1970.


In the example below, the myDate is declared and then the .setTime() method is applied to return a modified time.

const myDate = new Date();

This results in the following output:

Sun Jun 17 2021 12:30:45 GMT+0000 (Coordinated Universal Time)

All contributors

Looking to contribute?

Learn JavaScript on Codecademy