如何获得打字稿的unixtime
问题描述:
我在下面试过。如何获得打字稿的unixtime
var unixtime = new Date/1000;
然后,编译出错。
error TS2113: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.
如何获得unixtime没有编译错误?
答
使用+
运营商明确地转换为数字:
var x = +new Date/1000;
或者只是使用更快/更清晰的方法Date#now
:
var x = Date.now()/1000;
太感谢你了! – hidechae 2015-02-23 04:36:56
愚蠢的问题......那是什么+运营商......只是一个普通的加号? – Jeff 2017-08-25 16:51:49
是的,一元加号 – 2017-08-25 17:44:11