[javascript] How to get time in milliseconds since the unix epoch in Javascript?

Possible Duplicate:
How do you get a timestamp in JavaScript?
Calculating milliseconds from epoch

How can I get the current epoch time in Javascript? Basically the number of milliseconds since midnight, 1970-01-01.

This question is related to javascript

The answer is


Date.now() returns a unix timestamp in milliseconds.

_x000D_
_x000D_
const now = Date.now(); // Unix timestamp in milliseconds_x000D_
console.log( now );
_x000D_
_x000D_
_x000D_

Prior to ECMAScript5 (I.E. Internet Explorer 8 and older) you needed to construct a Date object, from which there are several ways to get a unix timestamp in milliseconds:

_x000D_
_x000D_
console.log( +new Date );_x000D_
console.log( (new Date).getTime() );_x000D_
console.log( (new Date).valueOf() );
_x000D_
_x000D_
_x000D_


This will do the trick :-

new Date().valueOf()