JS 和当前时间比较大小

来源:互联网 发布:适合女生的工作知乎 编辑:程序博客网 时间:2024/06/04 18:00

首先介绍一点小知识:

将时间中的格式“-”转化成“/”  

time1 = time1.replace(/-/g, "/");
 
比较函数:
 
var test = function () {
        var now = new Date();
        nowyear = now.getFullYear();
        nowmonth = now.getMonth() + 1;
        nowday = now.getDate();
        var today = nowyear + "-" + nowmonth + "-" + nowday;
        var time1 = $.trim($("#timeout").val());
        if (today > time1) {
            $("#messageStr").text("不能小于今天");
        }
        else {
            $("#messageStr").text("OK");
        }
        return false;
    }