Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

timestamp
javascript
get

How to get the timestamp in JavaScript

Educative Answers Team

The timestamp is the number of milliseconds elapsed since January 1, 1970. It is also known as the Unix time.

svg viewer

We can get this value using methods of the JavaScript date object:

  1. Use the valueOf() method (or + operator which invokes the valueOf() method):
console.log(new Date().valueOf());
   OR
console.log(+new Date());
  1. Use the now() method. This way, a Date object will not be created:
console.log(Date.now());

Example:

console.log(new Date().valueOf());
console.log(+new Date());
console.log(Date.now());

RELATED TAGS

timestamp
javascript
get
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring