js相关

判断是否是NaN不能用等号,要用isNaN,今天写在日期字段上增加值的方法,用==是错误的。
//在dDate基础上操作
cv.util.getDate=function(strInterval,Number,dDate){
	var dtTmpLong = Date.parse(dDate);
	var dtTmp;
	if(dtTmpLong==0 || isNaN(dtTmpLong)){
		dtTmp = new Date();
	}else{
		dtTmp = new Date(dDate); 
	}
	var r;
    switch (strInterval){
        case 's' :{r= new Date(Date.parse(dtTmp) + (1000 * Number));break};  
        case 'n' :{r= new Date(Date.parse(dtTmp) + (60000 * Number)); break};  
        case 'h' :{r=  new Date(Date.parse(dtTmp) + (3600000 * Number)); break};  
        case 'd' :{r= new Date(Date.parse(dtTmp) + (86400000 * Number)); break};  
        case 'w' :{r= new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number)); break};  
        case 'q' :{r= new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number*3, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); break};  
        case 'm' :{r= new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); break};  
        case 'y' :{r= new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); break};  
    }
    var year = r.getFullYear();       //年
    var month = (r.getMonth() + 1)<10?('0'+(r.getMonth() + 1)):(r.getMonth() + 1);     //月
    var day = r.getDate()<10?('0'+(r.getDate())):(r.getDate());;            //日
    return year+'-'+month+'-'+day;
};





你可能感兴趣的:(js相关)