Home > Article > Web Front-end > A simple way to compare date sizes in javascript_javascript skills
The example in this article describes how to simply compare date sizes in JavaScript. Share it with everyone for your reference, the details are as follows:
//获取起始日期 var startDate=document.all.startdate.value; //转换为日期格式 startDate=startDate.replace(/-/g,"/"); //获取结束日期 var endDate=document.all.enddate.value; endDate=endDate.replace(/-/g,"/"); //如果起始日期大于结束日期 if(Date.parse(startDate)-Date.parse(endDate)>0){ alert("起始日期要在结束日期之前!"); //返回false return false; }
I hope this article will be helpful to everyone in JavaScript programming.