javascript 比较当前日期

javascript 比较当前日期

function checkBeforeCurDate(inputMonth){
		var nowTime = new Date();
		
		var tmpIntYear = parseInt(inputMonth.substr(0,4),10);
		var tmpIntMonth = parseInt(inputMonth.substr(5,2),10);
		var tmpIntDay = parseInt(inputMonth.substr(8,2),10);
		if( tmpIntYear < nowTime.getFullYear() ){
			return true;
		}else if(tmpIntYear = nowTime.getFullYear()){
			if( tmpIntMonth < (nowTime.getMonth()+1) ){
				return true;
			}else if( tmpIntMonth == (nowTime.getMonth()+1) ){
				if(tmpIntDay < nowTime.getDate() ){
					return true;
				}else{
					return false;
				}
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
function checkInputDate(inputStartMonth,inputEndMonth){
		
		if( inputStartMonth ==null  || inputStartMonth==""){
			alert("开始日期为空");
			return false;
		}
		if( inputEndMonth ==null  || inputEndMonth==""){
			alert("结束日期为空");
			return false;
		}


		inputStartMonth =inputStartMonth .replaceAll("/","-"); 
		inputEndMonth =inputEndMonth .replaceAll("/","-"); 

		var arrStart = inputStartMonth.split("-");
		var tmpIntStartYear = parseInt(arrStart[0],10);
		var tmpIntStartMonth = parseInt(arrStart[1],10);
		
		var arrEnd = inputEndMonth.split("-");
		var tmpIntEndYear = parseInt(arrEnd[0],10);
		var tmpIntEndMonth = parseInt(arrEnd[1],10);
		
		if( tmpIntStartYear < tmpIntEndYear ){
			return true;
		}else if(tmpIntStartYear = tmpIntStartYear ){
			if( tmpIntStartMonth < tmpIntEndMonth ){
				return true;
			}else{
				alert("开始日期不能晚于结束日期");
				return false;
			}
		}else{
			alert("开始日期不能晚于结束日期");
			return false;
		}
		
		
	}
<html>
<body>

<script type="text/javascript">

var inputMonth="2012-12-14"
var nowTime = new Date();
		
		var tmpIntYear = parseInt(inputMonth.substr(0,4),10);
		var tmpIntMonth = parseInt(inputMonth.substr(5,2),10);
		var tmpIntDay = parseInt(inputMonth.substr(8,2),10);
		
		document.write("tmpIntYear="+tmpIntYear+";<br/>");
		document.write("tmpIntMonth="+tmpIntMonth+";<br/>");
		document.write("tmpIntDay="+tmpIntDay+";<br/>");
		document.write("<br/>");
		document.write("<br/>");
		
		
		document.write("nowTime.getFullYear()="+nowTime.getFullYear()+";<br/>");
		document.write("nowTime.getMonth()+1="+(nowTime.getMonth()+1)+";<br/>");
		document.write("nowTime.getDate()="+nowTime.getDate()+";<br/>");
		
		document.write("<br/>");
		document.write("<br/>");
		
		if( tmpIntYear < nowTime.getFullYear() ){
			document.write("return true;<br/>");
		}else if(tmpIntYear = nowTime.getFullYear()){
			if( tmpIntMonth < (nowTime.getMonth()+1) ){
				document.write("return true;<br/>");
			}else if( tmpIntMonth == (nowTime.getMonth()+1) ){
				if(tmpIntDay < nowTime.getDate() ){
					document.write("return true;<br/>");
				}else{
					document.write("DATE return FALSE         XXXXXXXXX;<br/>");
				}
			}else{
				document.write("Month return FALSE         XXXXXXXXX;<br/>");
			}
		}else{
			document.write("Year return FALSE         XXXXXXXXX;<br/>");
		}
		
		
document.write("<br/><br/><br/><br/><br/><br/><br/><br/><br/>");

</script>

</body>
</html>

相关推荐