0

我正在努力创造一个我可以轻松与他人联系起来的时间价值。

var created = Date.now() * 1000

var day_ago = Date.now() * 1000 - 24*60*60

if(created > day_ago){console.log('it was created in the last day')}

这似乎无法正常工作,任何人都知道我做错了什么

4

2 回答 2

1

Date.now() 将返回除以 1000 的毫秒数,以秒为单位进行转换。

var created = Date.now() / 1000

var day_ago = Date.now()/ 1000 - 24*60*60

if(created > day_ago){console.log('it was created in the last day')}
于 2012-11-10T18:49:47.463 回答
0

您必须除以 1000,而不是相乘

var created = Date.now() / 1000
var day_ago = Date.now() / 1000 - 24*60*60
if(created > day_ago){console.log('it was created in the last day')}
于 2012-11-10T18:48:44.547 回答