Files
30-seconds-of-code/snippets/fromTimestamp.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

460 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Date from Unix timestamp date number-2 2020-10-15T21:57:17+03:00 2020-10-15T21:57:17+03:00

Creates a Date object from a Unix timestamp.

  • Convert the timestamp to milliseconds by multiplying with 1000.
  • Use the Date constructor to create a new Date object.
const fromTimestamp = timestamp => new Date(timestamp * 1000);
fromTimestamp(1602162242); // 2020-10-08T13:04:02.000Z