easyUI—— datagrid 日期比较天数,小时

   //获取出差天数
            $('#ipt_begindatetime').datebox({
                onChange: function () {
                    var begindate = $('#ipt_begindatetime').datebox("getValue");
                    var enddate = $('#ipt_enddatetime').datebox("getValue");
                    if (begindate != "" && enddate != "") {
                        if (begindate.replace("-", "") <= enddate.replace("-", "")) {
                            var totaltime = DateDiff(enddate, begindate);
                            $('#ipt_egressiontotaltime').val(totaltime);
                        }
                        else {
                            $('#ipt_begindatetime').datebox("setValue", "");
                            $('#ipt_egressiontotaltime').val("");
                            $.messager.alert('提示', '开始时间不能大于开始时间', 'error');
                        }
                    }
                }
            });

            $('#ipt_enddatetime').datebox({
                onChange: function () {
                    var begindate = $('#ipt_begindatetime').datebox("getValue");
                    var enddate = $('#ipt_enddatetime').datebox("getValue");
                    if (begindate != "" && enddate != "") {
                        if (begindate.replace("-", "") <= enddate.replace("-", "")) {
                            var totaltime = DateDiff(enddate, begindate);
                            $('#ipt_egressiontotaltime').val(totaltime);
                        }
                        else {
                            $('#ipt_enddatetime').datebox("setValue", "");
                            $('#ipt_egressiontotaltime').val("");
                            $.messager.alert('提示', '结束时间不能小于开始时间', 'error');
                        }
                    }
                }
            });

   //计算小时差的函数,通用  
        function DateDiff(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式  
            var aDate, oDate1, oDate2, iHours
            aDate = sDate1.split("-")
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])    //转换为12-18-2006格式  
            aDate = sDate2.split("-")
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
            iHours = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60)    //把相差的毫秒数转换为小时
            return iHours
        }

 

 

        //计算天数差的函数,通用  
        function DateDiff(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式  
            var aDate, oDate1, oDate2, iDays
            aDate = sDate1.split("-")
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])    //转换为12-18-2006格式  
            aDate = sDate2.split("-")
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24)    //把相差的毫秒数转换为天数  
            return iDays
        }

 

posted @ 2015-12-17 11:38  怎能不累  阅读(1279)  评论(0编辑  收藏  举报