纯javascript判断查询日期是否为有效日期

var snapshot_createTime_begin=$(selector+" input[name='createTime_begin']").val().trim();
      var snapshot_createTime_end=$(selector +" input[name='createTime_end']").val().trim();
      try{
        //判断开始时间是否为有效的日期
        if(snapshot_createTime_begin!=""&&new Date(snapshot_createTime_begin).getDate()!=snapshot_createTime_begin.match(/-\d{0,2}$/g)[0].replace(/-/g,"")){
          throw new Error();
        }
        //判断结束时间是否为有效的日期
        if(snapshot_createTime_end!=""&&new Date(snapshot_createTime_end).getDate()!=snapshot_createTime_end.match(/-\d{0,2}$/g)[0].replace(/-/g,"")){
          throw new Error();
        }
        if(Date.parse(snapshot_createTime_begin)>Date.parse(snapshot_createTime_end)){
          //alert("开始日期不应当超过结束日期!");
          alert("开始日期不应当超过结束日期!");
          return ;
        }
        $.extend(pageObj,{
          createTimeBegin:snapshot_createTime_begin,
          createTimeEnd:snapshot_createTime_end,
        });
        initPagination();
      }catch(e){
        //alert("请输入有效日期!")
        alert("请输入有效日期!");
      }

js判断年月日是否一个有效日期

function isdate(intYear,intMonth,intDay){ 
 if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) return false;   
 if(intMonth>12||intMonth<1) return false; 
 if ( intDay<1||intDay>31)return false; 
 if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30)) return false; 
 if(intMonth==2){ 
   if(intDay>29) return false;  
   if((((intYear%100==0)&&(intYear%400!=0))||(intYear%4!=0))&&(intDay>28))return false; 
  }
 return true; 
}

以上代码就是对日期的有效性校验,希望对大家有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

评论“纯javascript判断查询日期是否为有效日期”

暂无评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。

更新日志

2024年09月21日