js時間比較(yyyymmdd)

3165 ワード

yyymmddフォーマットの時間比較例は、以下のコードを参照してください.
 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<script language="javascript" type="text/javascript"  src="js/DatePicker/WdatePicker.js"></script>
<script language="javascript">
function checkTime(){
	  	var begin=document.mainform.mod_begin.value;
	  	var end =document.mainform.mod_end.value;
	  	
	  	if(begin==""){
	  		alert("Please select start date");
	  		return false;
	  	}
	  	
	  	var today = new Date();
	  	var xYear=today.getFullYear();
    
	    var xMonth=today.getMonth()+1;
	    if(xMonth<10){
	        xMonth="0"+xMonth;
	    }

	    var xDay=today.getDate();
	    if(xDay<10){
	        xDay="0"+xDay;
	    }
	
	    var xHours=today.getHours();
	    if(xHours<10){
	        xHours="0"+xHours;
	    }
	
	    var xMinutes=today.getMinutes();
	    if(xMinutes<10){
	        xMinutes="0"+xMinutes;
	    }
	
	    var xSeconds=today.getSeconds();
	    if(xSeconds<10){
	        xSeconds="0"+xSeconds;
	    }

			var now = xYear+xMonth+xDay
			//alert("begin"+ begin +"| now = "+ now);
			
			if(begin < now) {
			  alert("The Order start Day can't earlyer than today!");
			  return false;
			}		
			  	
	  	if(end!=""){
	  			if(document.mainform.mod_begin.value>document.mainform.mod_end.value){//     
	  	       alert("The Order start Date can't larger than the end Date!");
	  	       return false;
	  	    }
	  	} 	
			
      
  	  document.mainform.action="action.do";
  	  document.mainform.submit();
}
</script>
</head>

<body leftmargin="6" topmargin="2" marginwidth="0" marginheight="0">

<form name="mainform" action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
      <td width="43%" align="center">Start Date:
          <input name="mod_begin"  value="" defaultvalue="false" onClick="WdatePicker()"></td>
      <td colspan="2" align="center">End Date:
          <input name="mod_end"  value="" defaultvalue="false" onClick="WdatePicker()"></td>
        </tr>
    <tr>
</table>
<input type="button" value="submit" onclick="checkTime();"/>
</form>

</body>
</html>
 
WdatePicker.jsは添付ファイルに会います.