Files
30-seconds-of-code/snippets/fromTimestamp.md
Isabelle Viktoria Maciohsek bdbd98cfc0 Add fromTimestamp
2020-10-15 21:57:17 +03:00

356 B

title, tags
title tags
fromTimestamp date,beginner

Creates a Date object from a Unix timestamp.

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