`

JS 对时间的比较

 
阅读更多
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    
    <title>管理</title> 
    
<meta http-equiv="pragma" content="no-cache"> 
<meta http-equiv="cache-control" content="no-cache"> 
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
<meta http-equiv="description" content="This is my page"> 
<!-- 
<link rel="stylesheet" type="text/css" href="styles.css"> 
--> 
<link rel="stylesheet" href="../../common/resources/css/all.css" type="text/css" /> 
<script language="javascript"> 
function checktime(str) 
{ 
//var re=/^([2-9][0-9][0-9][0-9])-((0[1-9])|(1[0-2]))-((3[0-1])|(0[1-9])|([1-2][0-9]))(([0-1][0-9])|(2[0-3])):([0-5][0-9])$/g; 
var re=/^([2-9][0-9][0-9][0-9])-((0[1-9])|(1[0-2]))-((3[0-1])|(0[1-9])|([1-2][0-9]))$/g; 
if(re.test(str)==false){return true;} 
} 
function CheckForm(){ 
form1.leaveReason.value=contedit.getHTML(); 
if(isNaN(form1.vacation.value) || form1.vacation.value==""){ 
alert('公休请假天数只能是数字。'); 
form1.vacation.focus(); 
return false; 
} 
if(form1.vacation.value>100){ 
alert('公休请假天数不能大于100天'); 
form1.vacation.focus(); 
return false; 
} 
///if(checktime(form1.vacationBDate.value)){ 
/// alert("错误的公休开始时间格式!"); 
/// form1.vacationBDate.focus(); 
/// return false; 
///} 
///if(checktime(form1.vacationEDate.value)){ 
/// alert("错误的公休结束时间格式!"); 
/// form1.vacationEDate.focus(); 
/// return false; 
///} 
///if(form1.vacationBDate.value>form1.vacationEDate.value){ 
/// alert('公休开始时间不能大于结束时间'); 
/// return false; 
///} 
if(isNaN(form1.privateAffair.value) || form1.privateAffair.value==""){ 
alert('事假请假天数只能是数字。'); 
form1.privateAffair.focus(); 
return false; 
} 
if(form1.privateAffair.value>100){ 
alert('事假请假天数不能大于100天'); 
form1.privateAffair.focus(); 
return false; 
} 
///if(checktime(form1.palBDate.value)){ 
/// alert("错误的事假开始时间格式!"); 
/// form1.palBDate.focus(); 
/// return false; 
///} 
///if(checktime(form1.palEDate.value)){ 
/// alert("错误的事假结束时间格式!"); 
/// form1.palEDate.focus(); 
/// return false; 
///} 
if(form1.palBDate.value>form1.palEDate.value){ 
alert('事假开始时间不能大于结束时间'); 
return false; 
} 
if(isNaN(form1.sick.value) || form1.sick.value==""){ 
alert('病假请假数只能是数值。'); 
form1.sick.focus(); 
return false; 
} 
if(form1.sick.value>100){ 
alert('病假请假数不能大于100。'); 
form1.sick.focus(); 
return false; 
} 
/// if(checktime(form1.sickBDate.value)){ 
/// alert("错误的病假开始时间格式!"); 
//// form1.sickBDate.focus(); 
/// return false; 
/// } 
/// if(checktime(form1.sickEDate.value)){ 
//// alert("错误的病假结束时间格式!"); 
/// form1.sickEDate.focus(); 
/// return false; 
/// } 
if(form1.sickBDate.value>form1.sickEDate.value){ 
alert('病假开始时间不能大于结束时间'); 
return false; 
} 
if(form1.vacation.value+form1.privateAffair.value+form1.sick.value<1){ 
alert('请假天数不能小于1天!'); 
return false; 
} 
if(form1.leaveReason.value == "") { 
alert("请假原因不能为空!"); 
return false; 
} 

if(form1.checkerID.value==null||form1.checkerID.value=="") 
{ 
alert("请选择审批者"); 
return false; 
} 

return true; 
} 

function toSetType(){ 
var lid=form1.type.options(form1.type.selectedIndex).value; 
form1.leaveType.value=lid; 
} 

function getDate(field,strBil) 
{ 
var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 
field.value = returnValue; 

} 

function getVacationStartDate(field,strBil)  //公假开始时间 
{ 
var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 

var endTime= document.getElementById("vacationEDate").value; 
if(endTime!="") 
{ 
var iDays =DateDiff(endTime,returnValue); 
   iDays=iDays+1; 
if(iDays>0) 
{ 
  document.getElementById("vacation").value=iDays; 
      field.value = returnValue; 
    } 
else 
  alert("你选择的时间不正确,请选择比结束时间早的时期"); 
}else 
    field.value = returnValue; 

   
} 
function getVacationDate(field,strBil)  ///结束公假时间 
{ 
var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 

var statTime= document.getElementById("vacationBDate").value; 
var iDays =DateDiff(returnValue,statTime); 
   iDays=iDays+1; 
if(iDays>0) 
{ 
  document.getElementById("vacation").value=iDays; 
      field.value = returnValue; 
    } 
else 
   alert("你选择的时间不正确,请选择比开始时间晚的时期"); 
} 

function getpalStartDate() 
{ 
  var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 

var endTime= document.getElementById("palEDate").value; 
if(endTime!="") 
{ 
var iDays =DateDiff(endTime,returnValue); 
   iDays=iDays+1; 
if(iDays>0) 
{ 
  document.getElementById("privateAffair").value=iDays; 
      field.value = returnValue; 
    } 
else 
  alert("你选择的时间不正确,请选择比结束时间早的时期"); 
}else 
    field.value = returnValue; 
} 


function getpalDate(field,strBil)  ///事假 
{ 
var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 

var statTime= document.getElementById("palBDate").value; 
var iDays =DateDiff(returnValue,statTime); 
    iDays=iDays+1; 
if(iDays>0) 
{ 
document.getElementById("privateAffair").value=iDays; 
field.value = returnValue; 
} 
else 
   alert("你选择的时间不正确,请选择比开始时间晚的时期"); 
  

} 

  function getsickStartDate(field,strBil)  ///公开病假 
   { 
     var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
   var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 
   var endTime= document.getElementById("sickEDate").value; 
if(endTime!="") 
{ 
var iDays =DateDiff(endTime,returnValue); 
   iDays=iDays+1; 
if(iDays>0) 
{ 
  document.getElementById("sick").value=iDays; 
      field.value = returnValue; 
    } 
else 
  alert("你选择的时间不正确,请选择比结束时间早的时期"); 
}else 
    field.value = returnValue; 
   } 
   
function getsickDate(field,strBil)  ///病假 
{ 
var url = "../../common/commons/datepicker/CalendarCn.htm?field=" + field ; 
var calWin = window.showModalDialog (url,window,"dialogHeight:210px;dialogWidth:226px;center:Yes;help: No; resizable: No; status: No"); 
var statTime= document.getElementById("sickBDate").value; 
var iDays =DateDiff(returnValue,statTime); 
  iDays=iDays+1; 
if(iDays>0) 
{ 
field.value = returnValue; 
document.getElementById("sick").value=iDays; 
} 
else 
  alert("你选择的时间不正确,请选择比开始时间晚的时期"); 
} 

function addTime(daynum,staObj,endObj) 
  { 
   var statime = staObj.value; 
      if(statime!=""&&daynum>0) 
       { 
         var  aDate,  oDate1,  oDate2,  iDays  ; 
         aDate  =  statime.split("-")  ; 
         oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])  ;  //转换为12-18-2006格式 
           
        
        var a = new Date(oDate1) 
            a = a.valueOf(); 
            a = a + (daynum-1) * 24 * 60 * 60 * 1000; 
a = new Date(a); 
   endObj.value=a.format('yyyy-MM-dd'); 
       } 
  } 
function CheckList() 
{ 
var myobject=document.getElementsByName('chkMail'); 
var mynum = myobject.length; 
if(mynum){ 
for (i=0; i<mynum; i++) { 
if(myobject[i].checked){ 
form1.checkerID.value = myobject[i].value; 
} 
} 
} 
} 


Date.prototype.format = function(format) 
        { 
                var o = 
                { 
                    "M+" : this.getMonth()+1, //month 
                    "d+" : this.getDate(),    //day 
                    "h+" : this.getHours(),   //hour 
                    "m+" : this.getMinutes(), //minute 
                    "s+" : this.getSeconds(), //second 
                    "q+" : Math.floor((this.getMonth()+3)/3), //quarter 
                    "S" : this.getMilliseconds() //millisecond 
                } 
                
                if(/(y+)/.test(format)) 
                format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
                for(var k in o) 
                if(new RegExp("("+ k +")").test(format)) 
                format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length)); 
                return format; 
        } 


  //计算天数差的函数,通用  
   function  DateDiff(sDate1,  sDate2){    //sDate1和sDate2是 s1  =  "2006-12-18"  s2  =  "2007-01-05" 
       var  aDate,  oDate1,  oDate2,  iDays  
       aDate  =  sDate1.split("-")  
       oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])    //转换为12-18-2006格式  
       aDate  =  sDate2.split("-")  
       oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])  
       iDays  =  parseInt((oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数  
       return  iDays  
   }    
   
   
   
</script> 
  </head> 
  
  <body style="background-color:transparent">  
  <div id="header"> 
        <div id="daohang">当前位置:请假管理>>请假发件箱>>请假申请</div> 
</div> 
<div id="line"></div> 
   <div class="divshape">   
        <table id="tabel" cellspacing="0" bordercolor="#000000" style="border:1px solid #91CEF2; font-size:12px;" width="100%"> 
      
          <tr id="biaotuo"> 
            <th style="text-align:left;"> 
   请假单 
            </th> 
          </tr> 
          <tr> 
            <td valign="top"><div align="center"> 
              <table width="100%" height="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="3D9BD0" style="font-size:12px;"> 
                <tr> 
                  <td  valign="top" bgcolor="#FFFFFF"><div align="center" class="STYLE2"> 
     <form name="form1" method="post" action="leaveam-save.action" onSubmit="return CheckForm()"> 
  <input name="leaveID" id="leaveID" type="hidden" value="<ww:property value="leaveID" />"> 
  <input name="leaveType" id="leaveType" type="hidden" value="<ww:property value="leaveType" />"> 
  <input name="sectionTime" id="sectionTime" type="hidden" value="A"> 
  <input type="hidden" name="param" value="<ww:property value="param"/>"> 
  <table width="100%" border="0" align="center" cellpadding="1" cellspacing="2"  bordercolor="#CCCCCC" style="font-size:12px;"> 
    <tr style="display:none"> 
      <td width="15%">请假开始日期:</td> 
      <td colspan="7"> <div style='float:left'> 
    
    <input name="beginDate" type="text" class="txb" size="15" value="<ww:property value="beginDate" />" > 
        
      </div> 
            <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" 

height="15" border="0" align="top" onClick="getDate(document.all.beginDate,'2')" style="cursor:hand"> 

</div> 

  </td> 
    </tr> 
     <tr> 
      <td width="12%">公休: 

  </td> 
    <td width="15%">请假开始日期</td> 
  <td width="15%"> 
      <div style='float:left'><input name="vacationBDate" id="vacationBDate"  type="text" class="txb" size="11" value="<ww:property 

value="vacationBDate" />"></div> 
        <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" height="15" 

border="0" align="top" onClick="getVacationStartDate(document.all.vacationBDate,'2')" style="cursor:hand"></div>   
  </td> 
  <td width="15%">请假结束日期</td> 
  <td width="15%"> 
      <div style='float:left'><input name="vacationEDate" id="vacationEDate"  type="text" class="txb" size="11" value="<ww:property 

value="vacationEDate" />"  /></div> 
        <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" height="15" 

border="0" align="top" onClick="getVacationDate(document.all.vacationEDate,'2')" style="cursor:hand"> </div>   

  
  </td> 
  
  <td width="10%">请假天数</td> 
  <td width="10%"> 
    <ww:if test="vacation!=null"> 
          <input name="vacation" id="vacation" type="text" value="<ww:property value="vacation" />" size="4" onchange="addTime(this.value,document.all.vacationBDate,document.all.vacationEDate)" > 
   </ww:if>   
      <ww:if test="vacation==null"> 
    <input name="vacation" id="vacation" type="text" value="0" size="4" onchange="addTime(this.value,document.all.vacationBDate,document.all.vacationEDate)"> 
   </ww:if>   
    

  </td> 

    </tr>   
     <tr> 
      <td width="12%" >事假:</td> 
       <td >请假开始日期</td> 
  <td > 
      <div style='float:left'><input name="palBDate" id="palBDate" type="text" class="txb" size="11" value="<ww:property value="palBDate" 

/>"></div> 
        <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" height="15" 

border="0" align="top" onClick="getpalStartDate(document.all.palBDate,'2')" style="cursor:hand"> </div>   
  </td> 
  <td>请假结束日期</td> 
  <td> 
      <div style='float:left'><input name="palEDate" type="text" class="txb" size="11" value="<ww:property value="palEDate" 

/>"></div> 
        <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" height="15" 

border="0" align="top" onClick="getpalDate(document.all.palEDate,'2')" style="cursor:hand"> </div>   

  
  </td> 
  
  <td >请假天数</td> 
  <td > 
  
   <ww:if test="privateAffair!=null"> 
          <input name="privateAffair" id="privateAffair" type="text" value="<ww:property value="privateAffair" />" size="4" onchange="addTime(this.value,document.all.palBDate,document.all.palEDate)" > 
   </ww:if>   
      <ww:if test="privateAffair==null"> 
    <input name="privateAffair" id="privateAffair" type="text" value="0" size="4" onchange="addTime(this.value,document.all.palBDate,document.all.palEDate)"> 
   </ww:if>   
    
  </td> 

    </tr>     
     <tr> 
      <td width="12%" >病假:</td> 
        <td>请假开始日期</td> 
  <td> 
      <div style='float:left'><input name="sickBDate" id="sickBDate" type="text" class="txb" size="11" value="<ww:property 

value="sickBDate" />"></div> 
        <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" height="15" 

border="0" align="top" onClick="getsickStartDate(document.all.sickBDate,'2')" style="cursor:hand"> </div>   
  </td> 
  <td>请假结束日期</td> 
  <td> 
      <div style='float:left'><input name="sickEDate" type="text" class="txb" size="11" value="<ww:property 

value="sickEDate" />"></div> 
        <div style='float:left'><img src="../../common/resources/img/DatePicker.gif" alt="日期选择" width="17" height="15" 

border="0" align="top" onClick="getsickDate(document.all.sickEDate,'2')" style="cursor:hand"> </div>   

  
  </td> 
  
  <td >请假天数</td> 
  <td > 
    <ww:if test="sick!=null"> 
          <input name="sick" id="sick" type="text" value="<ww:property value="sick" />" size="4" onchange="addTime(this.value,document.all.sickBDate,document.all.sickEDate)"> 
   </ww:if>   
      <ww:if test="sick==null"> 
    <input name="sick" id="sick" type="text" value="0" size="4"  onchange="addTime(this.value,document.all.sickBDate,document.all.sickEDate)"> 
   </ww:if>   
    
    
  </td> 

    </tr>               
    <tr style="display:none"> 
      <td width="12%">请假类型:</td> 
      <td colspan="7"> 
<select name="type" onChange="toSetType()"> 
<option value="0" selected>公休</option> 
<option value="1">事假</option> 
<option value="2">病假</option> 
</select> 
  </td> 
    </tr> 
    <tr style="display:none"> 
      <td width="12%"><div align="right">请假数:</div></td> 
      <td colspan="7"> 
<input name="leaveCount" id="leaveCount" type="text" value="<ww:property value="leaveCount" />" size="30"> 
  </td> 
    </tr>      
    <tr> 
      <td width="12%"><div>请假审批组:</div></td> 
      <td colspan="7"> 
<table align="left"> 
<ww:iterator value="roleUserList" status="li"> 
<tr> 
<td> 
<input type="hidden" name="usersID"  value="<ww:property 

value="userID" />"> 
<input type="hidden" name="usersAccount"  value="<ww:property 

value="account" />"> 
<input type="hidden" name="usersName"  value="<ww:property 

value="userName" />"> 
<input name="chkMail" type="radio" value="<ww:property value="userID" 

/>" onClick="CheckList()"> 
</td> 
<td style="display:none"><span style="font-size:11px"><ww:property 

value="account"/></span></td> 
<td><ww:property value="userName" /></td> 
</tr> 
</ww:iterator> 
</table> 
  </td> 
    </tr>       
    <tr> 
      <td width="12%"><div align="center">请假原因:</div></td> 
      <td colspan="6"> 
<input name="leaveReason" id="leaveReason" type="hidden" value="<ww:property value="leaveReason" />" 

size="30"> 
<INPUT type="hidden" name="content1" value="<ww:property value="leaveReason" />"> 
<IFRAME ID="contedit" src="../../common/editor/ewebeditor.htm?id=content1&style=noimg" frameborder="0" 

scrolling="no" width="550" height="250"></IFRAME> 
  </td> 
    </tr>    
<tr> 
<td colspan="8"> 
      <div align="center"> 
    <input name="checkerID" type="hidden" value=""> 
    <input name="oper" type="hidden" value="<ww:property value="oper" />"> 
    <input name="operType" type="hidden" value="<ww:property value="operType" />"> 
    <input name="checkStatus" id="checkStatus" type="hidden" value="0"> 
    <input name="readStatus" id="readStatus" type="hidden" value="0"> 
<input type="submit" name="ok" value="提交" class="button" 
onMouseOver="this.className='button1'" onMouseOut="this.className='button'"> 
<input type="reset" name="clear" value="重填" class="button" 
onMouseOver="this.className='button1'" onMouseOut="this.className='button'"> 
<input type="button" name="close" value="返回" class="button" 
onMouseOver="this.className='button1'" onMouseOut="this.className='button'" 
onclick="javascript:history.go(-1);"> 
        </div></td> 
</tr> 
  </table> 
  </form> 
  
                    </div></td> 
                </tr> 
              </table> 
            </div></td> 
          </tr> 
        </table> 
      </div>  
      
  </body> 
  <script type="text/javascript"> 
  form1.vacation.focus(); 
  </script> 
</html> 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics