js-判断一个时间是否在某个时间段内


先封装函数,功能为:判断一个时间是否在某个时间段内:

function isTimes(newdate, startdate, enddate) {
    var newdate = new Date(newdate);
    var startdate = new Date(startdate);
    console.log(newdate);
    console.log(startdate);
    var enddate = new Date(enddate);
    var a = newdate.getTime() - startdate.getTime();
    var b = newdate.getTime() - enddate.getTime();
    console.log(a);
    console.log(b);
    if (a < 0 || b > 0) {
        return '不在当前时间段内';
    } else {
        return '在当前时间段内';
    }
}

接下来调用封装好的函数实现对应的需求:

console.log(isTimes('2020-03-11 00:00:01','2020-03-11 00:00:01','2020-05-10 10:10:12'));   //在当前时间段内
 
 
如果感觉对自己有帮助,麻烦点一下关注,会一直和大家分享知识的,谢谢!!!
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM