js 中时间相减

var addDate = "获取到你想要的时间";//注意时间格式是:2012-03-05 11:41:30.910 addDate = new Date(Date.parse(addDate.replace(/\-/g, "/"))); var now = new Date(); var diff = now.getTime() - addDate.getTime(); //判断大于七天 if (addDate == 'NaN' || diff > 0 && diff > 7 * 24 * 60 * 60 * 1000) { art(""); }

你可能感兴趣的:(js)