js获得日期,以及日期的校验

js 代码
  1. //get the date string of today (1985/11/16)   
  2. function getDateString()...{   
  3.     var myDate=new Date();   
  4.     //get the full year(4 number,1970-????)   
  5.     var year=myDate.getFullYear();   
  6.     //get the month(0-11,0 is Jan)   
  7.     var monthNum=myDate.getMonth();   
  8.     var month;   
  9.     if(monthNum<9)...{   
  10.         month="0"+(monthNum+1);   
  11.     }else...{   
  12.         month=monthNum+1;   
  13.     }   
  14.      //get day(1-31)   
  15.     var day=myDate.getDate();   
  16.     if(day<9)...{   
  17.         day="0"+day;   
  18.     }   
  19.     var today=year+"/"+month+"/"+day   
  20.     return today;   
  21. }  
js 代码
  1. //验证文本框不能为空   
  2. function checkNull()...{   
  3.     var   checkItems=new   Array( "date""timeFrom","timeTo");   
  4.     msgArray=...{   
  5.         "date":"createTimesheet.date",   
  6.         "timeFrom":"createTimesheet.timeFrom",   
  7.         "timeTo":"createTimesheet.timeTo"  
  8.     };   
  9.     for(i in checkItems)...{   
  10.         var item=document.getElementById(checkItems[i]);   
  11.         var text=item.value;   
  12.         if(text==null||text=="")...{   
  13.             alert(msgArray[checkItems[i]]);   
  14.             return false;   
  15.         }   
  16.     }   
  17.     var temp=document.mainForm.date.value;   
  18.     if(temp==null||temp=="")...{   
  19.         alert("createTimesheet.date" />");   
  20.         return false;   
  21.     }   
  22.     return true;   
  23. }  
java 代码
  1. //校验2007/11/30 格式的日期,不正确的返回false   
  2. //字符串替换  全局替换“/”chkDate=chkDate.replace(///g,"");   
  3. //全局替换 a换成b chkDate=chkDate.replace(/a/g,"b");   
  4. //替换一个a换成b chkDate=chkDate.replace("a","b");   
  5. function checkSlashYyyymmdd(sDate)...{   
  6.     var chkDate=sDate;   
  7.     if(chkDate.length !=10)...{   
  8.         return false;   
  9.     }   
  10.     if (chkDate.charAt(4) != "/")...{   
  11.         return false;   
  12.     }   
  13.     if (chkDate.charAt(7) != "/")...{   
  14.         return false;   
  15.     }   
  16.     var yyyy=chkDate.substring(0,4);   
  17.     var mm=chkDate.substring(5,7);   
  18.     if(isNaN(mm)==true)...{   
  19.         return false;   
  20.     }   
  21.     mm=parseInt(mm);   
  22.     var dd=chkDate.substring(8,10);   
  23.     var Dt;   
  24.   
  25.     Dt=new Date(yyyy,mm-1,dd);   
  26.     if ((Dt.getFullYear()==yyyy) && (Dt.getMonth()+1==mm) && (Dt.getDate()==dd))...{   
  27.         return true;   
  28.     }   
  29.     return false;   
  30. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值