Reputation: 11676
I'm trying to create a time value I can easily relate to others.
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')}
This doesn't seem to work correctly, anyone know what I'm doing wrong
Upvotes: 0
Views: 242
Reputation: 23208
Date.now() will return milli seconds devide by 1000 will convert that in seconds.
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')}
Upvotes: 1
Reputation: 1005
You must divide by 1000, not multiply
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')}
Upvotes: 0