From bdbd98cfc0ba36d2b830ac6f06f65a2923adfa4f Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Thu, 15 Oct 2020 21:57:17 +0300 Subject: [PATCH] Add fromTimestamp --- snippets/fromTimestamp.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/fromTimestamp.md diff --git a/snippets/fromTimestamp.md b/snippets/fromTimestamp.md new file mode 100644 index 000000000..177820df0 --- /dev/null +++ b/snippets/fromTimestamp.md @@ -0,0 +1,17 @@ +--- +title: fromTimestamp +tags: 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. + +```js +const fromTimestamp = timestamp => new Date(timestamp * 1000); +``` + +```js +fromTimestamp(1602162242); // 2020-10-08T13:04:02.000Z +```