How to convert timestamp to date object in JavaScript?

The JavaScript date object is quite rich. We can easily convert timestamp to date object. We need to check wheather the timestamp is a unix timestamp or a timestamp return by the JavaScript methods.

Convert to timestamp examples

Let us consider the following unix timestamp.

let unixTimestamp = 1618447140;

Convert unix timestamp

console.log(new Date(unixTimestamp * 1000));
// Output: Thu Apr 15 2021 06:39:00 GMT+0600

Convert JS timestamp

let jsTimestamp = 1616695200000;
// Output: Fri Mar 26 2021 00:00:00 GMT+0600
Share