Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a unix timestamp to a Date in TypeScript?

In plain JavaScript and TypeScript we can write the following to obtain the unix timestamp of a Date:

let d = new Date();
const unixtime = d.valueOf();

Now, in JavaScript, we can easily convert that unix timestamp back to a Date:

d = new Date(unixtime);

However, in TypeScript, the above returns an error message:

error TS2554: Expected 0 arguments, but got 1.

So how can I convert a unix timestamp to a date in TypeScript? I'm using ES6 library

like image 765
msrd0 Avatar asked Jan 05 '18 00:01

msrd0


Video Answer


1 Answers

in TypeScript, the above returns an error message:

There is no error in current TypeScript:

enter image description here

Fix

Update TypeScript to latest 🌹

like image 194
basarat Avatar answered Oct 29 '22 00:10

basarat