日期比较
程序员文章站
2022-05-19 22:57:07
...
比较日期:
function compareDate(source){ var dateFromVal = document.getElementById("dateFrom").value; var dateToVal = document.getElementById("dateTo").value; var d1Arr=dateFromVal.split('-'); var d2Arr=dateToVal.split('-'); var v1=new Date(d1Arr[0],d1Arr[1],d1Arr[2]); var v2=new Date(d2Arr[0],d2Arr[1],d2Arr[2]); if(dateFromVal != "" && dateToVal != ""){ if(v1 > v2){ if(source == "from"){ alert("开始日期不能大于结束日期,请重新选择!"); }else if(source == "to"){ alert("结束日期不能小于开始日期,请重新选择!"); } } } }
dojo方式,实际上还是js方式
require(["dojo/dom","dojo/on","dojo/query","dojo/domReady!"],function(dom, on,query){ on(dom.byId("search"),"click",function(){ var dateFromVal = document.getElementById("dateFrom").value; var dateToVal = document.getElementById("dateTo").value; var startdate=dateFromVal.split("-"); var enddate=dateToVal.split("-"); var starttime = new Date(startdate[0],startdate[1],startdate[2]); var starttimes = starttime.getTime(); var endtime = new Date(enddate[0],enddate[1],enddate[2]); var lktimes = endtime.getTime(); if(starttimes > lktimes){ alert("开始日期不能大于结束日期,请重新选择!"); return false; } }); });