JS传入日期(XXXX-XX-XX格式)与当前日期比较

            //传入日期与当前日期比较
            function compareDate(myDate){
                console.log("myDate "+myDate);
                var d = new Date();
                var today = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();//获得今天时间
                console.log("today "+today);
                d.setTime(d.getTime()+24*60*60*1000);
                var tomorrow = d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();//获得今天时间
                console.log("tomorrow "+tomorrow);
                if(myDate===today){
                    return "今天";//是当前日期,返回今天
                }else if(myDate===tomorrow){
                    return "明天";//非当前日是明天,明天
                }else{
                    return myDate;//非当前日期,直接返回日期
                }
            }

你可能感兴趣的:(个人,jquery)