.valueOf()

Anonymous contributor's avatar
Anonymous contributor
Published Jul 22, 2021Updated May 31, 2023
Contribute to Docs

Returns the difference in milliseconds between the specified date and January 1, 1970 00:00:00 UTC.

Syntax

myDate.valueOf();

Example 1

Print the value of January, 1st, 1970 at 12:00:00 AM.

const date = new Date(1999, 00, 01, 0, 0, 0, 0);
console.log(date);
// Output: Fri Jan 01 1999 00:00:00 GMT-0800 (Pacific Standard Time)
// Note: Timezone may vary
console.log(date.valueOf());
// Output: 915177600000

Codebyte Example

The following is runnable, and demonstrates the use of the .valueOf() method.

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy