EN
JavaScript - convert unix milliseconds time to Date
0
points
In this article, we would like to show you how to convert unix milliseconds time to Date in JavaScript.
Quick solution:
// ONLINE-RUNNER:browser;
const timestamp = 1630564245000; // unix timestamp in milliseconds
const date = new Date(timestamp);
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 (in milliseconds) to the Date object.
// ONLINE-RUNNER:browser;
const getDate = (timestamp) => {
return new Date(timestamp);
};
// Usage example:
const timestamp = 1630564245000; // unix timestamp in milliseconds
const date = getDate(timestamp);
console.log(date.toISOString()); // 2021-09-02T06:30:45.000Z
Output:
2021-09-02T06:30:45.000Z