Languages
[Edit]
EN

JavaScript - convert unix timestamp to Date

3 points
Created by:
Aston-Freeman
787

In this article, we would like to show you how to convert unix timestamp to Date in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

const timestamp = 1630564245;     // unix timestamp in seconds
const date = new Date(timestamp * 1000);

console.log(date.toISOString());  // 2021-09-02T06:30:45.000Z

 

Practical example

In this example, we simply use the Date() constructor and pass timestamp as an argument to convert unix timestamp to the Date object.

// ONLINE-RUNNER:browser;

const getDate = (timestamp) => {
	return new Date(timestamp * 1000);
};

// Usage example:

const timestamp = 1630564245;     // unix timestamp in seconds
const date = getDate(timestamp);

console.log(date.toISOString());  // 2021-09-02T06:30:45.000Z

Output:

2021-09-02T06:30:45.000Z

Alternative titles

  1. JavaScript - convert unix seconds time to Date
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - convert unix timestamp to Date

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join