How to get a timestamp in seconds in JavaScript?

September 29, 2022 No comments timestamp seconds javascript tips solutions

Introduction

In JavaScript, we may wish to get a timestamp in seconds.

We'll examine how to get a timestamp in seconds in this tutorial.

How to get a timestamp in seconds in JavaScript

To get the number of seconds since the Unix epoch use the following method:

console.log(Math.floor(Date.now() / 1000));

Conclusion

To get a timestamp in seconds in JavaScript we can use Date.now() and divide its value by a thousand.

To get timestamp in milliseconds simply use Date.now() static method.

{{ message }}

{{ 'Comments are closed.' | trans }}