javascript两个时间跨度计算

function computeDateLength(){

            var leave=$("#ctl00_ContentPlaceHolder1_txtLeaveDate").val();

            var back=$("#ctl00_ContentPlaceHolder1_txtBackDate").val();

            var leavedate=new Date(leave.split(' ')[0].replace(/\-/g, "\/"))

            var backdate=new Date(back.split(' ')[0].replace(/\-/g, "\/"));

            var computedate=(backdate-leavedate)/86400000;//计算日期跨度

            var leavehour=leave.split(' ')[1].split(':')[0];

            var backhour=back.split(' ')[1].split(':')[0];

            var computehour=backhour-leavehour<0?24+(backhour-leavehour):backhour-leavehour;//计算小时跨度

            var leaveminute=leave.split(' ')[1].split(':')[1];

            var backminute=back.split(' ')[1].split(':')[1];

            var computeminute=backminute-leaveminute<0?60+(backminute-leaveminute):backminute-leaveminute;//计算分钟跨度

            computedate=backhour-leavehour<0?computedate-1:computedate;

            computehour=backminute-leaveminute<0?computehour-1:computehour;

            $("#ctl00_ContentPlaceHolder1_txtqjcd").val(computedate+"天"+computehour+" 时"+computeminute+" 分");

        }

你可能感兴趣的:(JavaScript)