Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get unixtime with typescript

Tags:

typescript

I tried below.

var unixtime = new Date / 1000;

then, compilation error occured.

error TS2113: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.

How to get unixtime with no compilation error ?

like image 545
hidechae Avatar asked Dec 14 '22 16:12

hidechae


1 Answers

Use the + operator to explicitly convert to a number:

var x = +new Date / 1000;

Or just use the faster / clearer method Date#now:

var x = Date.now() / 1000;
like image 94
Ryan Cavanaugh Avatar answered Dec 27 '22 00:12

Ryan Cavanaugh