JavaScript .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.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

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

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours