js时间比较/当前时间

var selectDate=edit.getControl("FRequestTime").element.find("input").val().substring(0,10);
 var result=new Date().Format("yyyy-MM-dd");
 var date1=selectDate.replace(/-/g, "");//选择时间
 var date2=result.replace(/-/g, "");//当前时间
 if(date1-date2<n){
  Dialog.alert("需提前三天发货申请");
 }

 

 

 

Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}

 

 

 

function getNowFormatDate() {

    var date = new Date();

    var seperator1 = "-";

    var month = date.getMonth() + 1;

    var strDate = date.getDate();

    if (month >= 1 && month <= 9) {

        month = "0" + month;

    }

    if (strDate >= 0 && strDate <= 9) {

        strDate = "0" + strDate;

    }

    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;

    return currentdate;

}

猜你喜欢

转载自lanrikey.iteye.com/blog/2261544