Home  >  Article  >  Web Front-end  >  A simple way to compare date sizes in javascript_javascript skills

A simple way to compare date sizes in javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:21:371059browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn