function isToday(str) { var d = new Date(str.replace(/-/g, "/")); var todaysDate = new Date(); if (d.setHours(0, 0, 0, 0) == todaysDate.setHours(0, 0, 0, 0)) { return true; } else { return false; } }
by default7#zbphp.com
自己改动。添加diff參数。 diff为天数
function isToday(str, diff) { var d = new Date(str.replace(/-/g, "/")); var todaysDate = new Date(); if (!isNaN(diff)) { d.setDate(d.getDate() + diff); } if (d.setHours(0, 0, 0, 0) == todaysDate.setHours(0, 0, 0, 0)) { return true; } else { return false; } }
版权声明:本文博主原创文章,博客,未经同意不得转载。