JS比較2個日期間隔的示例代碼
更新時間:2014年04月15日 15:58:39 作者:
這篇文章主要介紹了JS比較2個日期間隔的方法,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<!--forms[]部分-->
<td>
<div id="td12Div" style="display: none;">起始日期:</div>
</td>
<td>
<div id="sdateDiv">
<date:date styleClass="psm-ui-text" name="startDate" property="startDate" divname="dayScope2"
sourceFormat="yyyy-MM-dd" targetFormat="yyyy-MM-dd" readonly="true"/>
</div>
</td>
<!--js部分-->
var startDate=document.forms[0].startDate.value;
var endDate=document.forms[0].endDate.value;
if(DateDiff(endDate,startDate)>3){
alert("日范圍不要超過三天");
return;
}
function DateDiff(endDate,startDate)
{
var arrDate,objDate1,objDate2,intDays;
arrDate=endDate.split("-");
objDate1=new Date(arrDate[1]+'-'+arrDate[2]+'-'+arrDate[0]);
arrDate=startDate.split("-");
objDate2=new Date(arrDate[1] + '-'+arrDate[2]+'-'+arrDate[0]);
intDays=parseInt(Math.abs(objDate1-objDate2)/1000/60/60/24);
return intDays;
}
相關(guān)文章
詳述 Sublime Text 打開 GBK 格式中文亂碼的解決方法
這篇文章主要介紹了詳述 Sublime Text 打開 GBK 格式中文亂碼的解決方法,非常具有實用價值,需要的朋友可以參考下2017-10-10
JS Jquery 遍歷,篩選頁面元素 自動完成(實現(xiàn)代碼)
本篇文章是對JS Jquery 遍歷,篩選頁面元素 自動完成的實現(xiàn)代碼進行了詳細的分析介紹,需要的朋友參考下2013-07-07
javascript之水平橫向滾動歌詞同步的應(yīng)用
javascript之水平橫向滾動歌詞同步的應(yīng)用...2007-05-05
JavaScript棧和隊列相關(guān)操作與實現(xiàn)方法詳解
這篇文章主要介紹了JavaScript棧和隊列相關(guān)操作與實現(xiàn)方法,結(jié)合實例形式較為詳細的分析了javascript棧和隊列的概念、原理、定義、用法及相關(guān)操作注意事項,需要的朋友可以參考下2018-12-12

