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>
相关推荐
nmgxzm00 2020-11-10
ifconfig 2020-10-14
hhanbj 2020-11-17
zfszhangyuan 2020-11-16
古叶峰 2020-11-16
一个智障 2020-11-15
jipengx 2020-11-12
81427005 2020-11-11
xixixi 2020-11-11
游走的豚鼠君 2020-11-10
苗疆三刀的随手记 2020-11-10
Web卓不凡 2020-11-03
小飞侠V 2020-11-02
帕尼尼 2020-10-30
爱读书的旅行者 2020-10-26
帕尼尼 2020-10-23
杏仁技术站 2020-10-23
淼寒儿 2020-10-22