时间大小对比

版权声明:复制发表请附上原创博客地址 https://blog.csdn.net/weixin_41077029/article/details/84633936

案例:比较2014-10-12 10:10 与2018-4-14  12:12的大小

//方法
function compareSizes(d1,d2){
    let dt1 = new Date(d1.replace(/-/g,"\/"))
    let dt2 = new Date(d2.replace(/-/g,"\/"))
    if(dt1>dt2){
        console.log("d1大于d2")
    }else{
        console.log("d1小于等于d2")
    }

}    
//方法调用   
let d1="2014-10-12 10:10"
let d2="2018-4-14  12:12"
compareSizes(d1,d2)

猜你喜欢

转载自blog.csdn.net/weixin_41077029/article/details/84633936