js 比较时间大小

function compareDate(DateOne, DateTwo)
        {
            var OneMonth = DateOne.substring(5, DateOne.lastIndexOf("-"));
            var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf("-") + 1);
            var OneYear = DateOne.substring(0, DateOne.indexOf("-"));

            var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf("-"));
            var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf("-") + 1);
            var TwoYear = DateTwo.substring(0, DateTwo.indexOf("-"));

            if (Date.parse(OneMonth + "/" + OneDay + "/" + OneYear) >
                Date.parse(TwoMonth + "/" + TwoDay + "/" + TwoYear))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        function submitForm()
        {
            if (compareDate(form1.starttime.value, form1.endtime.value))
            {
                alert("开始时间应在结束时间之前.");
                return false;
            }
            form1.submit();
        }

你可能感兴趣的:(js)