Date.valueOf()

Returns the primitive value of a Date object

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

var date1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5));

console.log(date1.valueOf());
// expected output: 823230245000

var date2 = new Date('02 Feb 1996 03:04:05 GMT');

console.log(date2.valueOf());
// expected output: 823230245000

Syntax

dateObj.valueOf()

Return value

The number of milliseconds between 1 January 1970 00:00:00 UTC and the given 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

References

Contributors to this page

Uros Durdevic

Last updated