How to convert a unix timestamp to a Date in TypeScript?
16,162
in TypeScript, the above returns an error message:
There is no error in current TypeScript:
Fix
Update TypeScript to latest 🌹
Author by
msrd0
I'm a backend developer from Germany, currently studying at the RWTH Aachen University. I started with Java, but quickly jumped to C++. Currently, my absolute favourite programming language is Rust, but I also use Kotlin from time to time.
Updated on June 05, 2022Comments
-
msrd0 almost 2 years
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