This example describes the JS simple time comparison method. Share to everyone for your reference, specific as follows:
Time comparison (YYYY-MM-DD) function comparedate (StartDate, EndDate) {var arrstart = Startdate.split ("-");
var starttime = new Date (arrstart[0], arrstart[1], arrstart[2]);
var starttimes = Starttime.gettime ();
var arrend = Enddate.split ("-");
var endtime = new Date (arrend[0], arrend[1], arrend[2]);
var endtimes = Endtime.gettime ();
if (endtimes<starttimes) {alert ("End time cannot be less than start time");
return false;
return true; }//Time comparison (Yyyy-mm-dd HH:mm:ss) function Comparetime (starttime,endtime) {var starttimes = starttime.substring (0). spli
T ('-');
var endtimes = endtime.substring (0). Split ('-');
StartTime = starttimes[1] + '-' + starttimes[2] + '-' + starttimes[0] + ' + starttime.substring (10, 19);
Endtime = endtimes[1] + '-' + endtimes[2] + '-' + endtimes[0] + ' + endtime.substring (10, 19);
var Thisresult = (Date.parse (endtime)-Date.parse (StartTime))/3600/1000; if (Thisresult < 0) {alert ("Endtime is less than tarttime!
"); else if (Thisresult > 0){Alert ("Endtime is greater than tarttime!
"); else if (Thisresult = 0) {alert ("Endtime equals tarttime!
");
else {return ' exception ';
}
}
PS: For JavaScript time and date operations interested friends can also refer to the site online tools:
Unix timestamp (timestamp) conversion tool:
Http://tools.jb51.net/code/unixtime
Online Worldwide Time query:
Http://tools.jb51.net/zhuanhuanqi/worldtime
Online Perpetual calendar:
Http://tools.jb51.net/bianmin/wannianli
Web calendar:
Http://tools.jb51.net/bianmin/webwannianli
More about JavaScript related content to view the site topics: "JavaScript time and date Operation skills Summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary", "JavaScript traversal algorithm and Skills summary" and "JavaScript Mathematical operation Usage Summary"
I hope this article will help you with JavaScript programming.