The timestamp is the number of milliseconds elapsed since January 1, 1970. It is also known as the Unix time.
We can get this value using methods of the JavaScript date object:
valueOf()
method (or +
operator which invokes the valueOf()
method):console.log(new Date().valueOf());
OR
console.log(+new Date());
now()
method. This way, a Date
object will not be created:console.log(Date.now());
console.log(new Date().valueOf());console.log(+new Date());console.log(Date.now());