欢迎光临
我们一直在努力

在javascript 里面有没有检查日期格式的函数?

建站超值云服务器,限时71元/月

function isdate(strdate){<br>

&nbsp;&nbsp;&nbsp;var strseparator = &quot;-&quot;; //日期分隔符<br>

&nbsp;&nbsp;&nbsp;var strdatearray;<br>

&nbsp;&nbsp;&nbsp;var intyear;<br>

&nbsp;&nbsp;&nbsp;var intmonth;<br>

&nbsp;&nbsp;&nbsp;var intday;<br>

&nbsp;&nbsp;&nbsp;var boolleapyear;<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;strdatearray = strdate.split(strseparator);<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;if(strdatearray.length!=3) return false;<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;intyear = parseint(strdatearray[0],10);<br>

&nbsp;&nbsp;&nbsp;intmonth = parseint(strdatearray[1],10);<br>

&nbsp;&nbsp;&nbsp;intday = parseint(strdatearray[2],10);<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;if(isnan(intyear)||isnan(intmonth)||isnan(intday)) return false;<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;if(intmonth&gt;12||intmonth&lt;1) return false;<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;if((intmonth==1||intmonth==3||intmonth==5||intmonth==7||intmonth==8||intmonth==10||intmonth==12)&&(intday&gt;31||intday&lt;1)) return false;<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;if((intmonth==4||intmonth==6||intmonth==9||intmonth==11)&&(intday&gt;30||intday&lt;1)) return false;<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;if(intmonth==2){<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(intday&lt;1) return false;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;boolleapyear = false;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((intyear%100)==0){<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((intyear%400)==0) boolleapyear = true;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else{<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if((intyear%4)==0) boolleapyear = true;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(boolleapyear){<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(intday&gt;29) return false;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else{<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(intday&gt;28) return false;<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>

&nbsp;&nbsp;&nbsp;}<br>

&nbsp;&nbsp;&nbsp;<br>

&nbsp;&nbsp;&nbsp;return true;<br>

}<br>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在javascript 里面有没有检查日期格式的函数?
分享到: 更多 (0)

相关推荐

  • 暂无文章