javascript 比量str今天的日期是,参数diff

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;
    }
}


版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-09-27 10:15  lcchuguo  阅读(222)  评论(0编辑  收藏  举报