Blog/content/posts/2023/javascript/timestamp-to-date.md

16 lines
469 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "📅 Преобразовать timestamp в Date на JavaScript"
date: 2023-06-11T18:46:36+03:00
draft: false
tags: [javascript, tips]
---
Необходимо `timestamp` умножить на `1000`,
поскольку JavaScript отсчитывает время с момента **epoch** (который равен `01/01/1970`)
в миллисекундах, а не в секундах.
```javascript
let date = new Date(timestamp * 1000);
```