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

A simple way to compare date sizes in javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:21:37
Original
1137 people have browsed it

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;
}

Copy after login

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template