an item in a webshop has a timestamp, if x time passed i want the item removed
so, a开发者_StackOverflow中文版ll the items in my webshop have timestamps on them. the date is updated every time the item is available and it will not update once the item has become unavailable. so far so good. for example now there is an item that was last available on 2010-09-25 (this is the format of the timestamp).
what i want to do now is removing this item from the listings, because it wasn't available for the past 30 days. the listings are in a div container, so all i really need to do is give the div a display:none style, which isn't the problem.
the problem is, that i don't know how to code the "if 30 days passed" thing... any help with that would be appreciated, thanks! :)
var d = Date.parse("2010-09-25")); //in ms from 1970
var now = new Date().getTime(); //now in ms
var days = (now - d)/ (1000*60*60*24); //diff / 1 day in ms
if(days >= 30){
//hide your stuff
}
There are also a couple of libraries to handle date/time in javascript with built-in method for comparisons like this.
精彩评论