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


javascript 判断str日期是否是今天,参数diff,布布扣,bubuko.com

javascript 判断str日期是否是今天,参数diff

上一篇:Python中字符串的有趣玩法


下一篇:Python:eval的妙用和滥用