jquery获取当前时间比较日期

时间:2022-03-26 18:10:09
//获取当前时间,格式 2015-09-05 10:00:00.000
        function getnowtime() {
            var nowtime = new Date();
            var year = nowtime.getFullYear();
            var month = padleft0(nowtime.getMonth() + 1);
            var day = padleft0(nowtime.getDate());
            var hour = padleft0(nowtime.getHours());
            var minute = padleft0(nowtime.getMinutes());
            var second = padleft0(nowtime.getSeconds());
            var millisecond = nowtime.getMilliseconds(); millisecond = millisecond.toString().length == 1 ? "00" + millisecond : millisecond.toString().length == 2 ? "0" + millisecond : millisecond;
            return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "." + millisecond;
        }
        //补齐两位数
        function padleft0(obj) {
            return obj.toString().replace(/^[0-9]{1}$/, "0" + obj);
        }
 
 

$("#selectbtn").click(function(){
var dates=$("#timearea").val();
var arr=new Array();
arr=dates.split(" - ");
var now=getnowtime();
alert(arr[0]);
alert(now);
if($("#timearea").val()==''){
alert("请选择时间段");
}else if(arr[0]>now){
alert("查询起始日期不能大于当前日期");
}else{
$("#select").submit();
}


});