Date.prototype.valueOf()

The valueOf() method returns the primitive value of a Date object.

Syntax

valueOf()

Return value

The number of milliseconds between 1 January 1970 00:00:00 UTC and the given date, or NaN in case of an invalid date.

Description

The valueOf() method returns the primitive value of a Date object as a number data type, the number of milliseconds since midnight 01 January, 1970 UTC.

This method is functionally equivalent to the Date.prototype.getTime() method.

This method is usually called internally by JavaScript and not explicitly in code.

Examples

Using valueOf()

var x = new Date(56, 6, 17);
var myVar = x.valueOf();      // assigns -424713600000 to myVar

Specifications

Specification
ECMAScript Language Specification
# sec-date.prototype.valueof

Browser compatibility

BCD tables only load in the browser

See also