Files
30-seconds-of-code/snippets/fromTimestamp.md
Isabelle Viktoria Maciohsek e9019d4c20 Update formatting
2022-01-30 12:01:08 +02:00

20 lines
442 B
Markdown

---
title: fromTimestamp
tags: date,beginner
firstSeen: 2020-10-15T21:57:17+03:00
lastUpdated: 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.
```js
const fromTimestamp = timestamp => new Date(timestamp * 1000);
```
```js
fromTimestamp(1602162242); // 2020-10-08T13:04:02.000Z
```