当前位置:编程学习 > JS >>

js计算两个时间之间的天数差


                        //判断是否为闰年
                        function isLeapYear(year){
                        if(year % 4 == 0 && ((year % 100 != 0) || (year % 400 == 0)))
                        {
                             return true;
                        }
                        return false;
                        }
                        //判断前后两个日期
                        function validatePeriod(fyear,fmonth,fday,byear,bmonth,bday){
                        if(fyear < byear){
                        return true;
                        }else if(fyear == byear){
                        if(fmonth < bmonth){
                           return true;
                        } else if (fmonth == bmonth){
                           if(fday <= bday){
                            return true;
                           }else {
                            return false;
                           }
                        } else {
                           return false;
                        }
                        }else {
                        return false;
                        }
                        }
                    //计算两个日期的差值
                        function dateDiff(d1,d2){
                            var disNum=compareDate(d1,d2);
                            return disNum;
                        }
                        function compareDate(date1,date2)
                        {
                            var regexp=/^(\d{1,4})[-|\.]{1}(\d{1,2})[-|\.]{1}(\d{1,2})$/;
                            var monthDays=[0,3,0,1,0,1,0,0,1,0,0,1];
                            regexp.test(date1);
                            var date1Year=RegExp.$1;
                            var date1Month=RegExp.$2;
                            var date1Day=RegExp.$3;

                            regexp.test(date2);
                            var date2Year=RegExp.$1;
                            var date2Month=RegExp.$2;
                            var date2Day=RegExp.$3;

                       

补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,