js Date comparison (YYYY-MM-DD)
function Duibi (A, b) {
var arr = a.split ("-");
var starttime = new Date (arr[0], arr[1], arr[2]);
var starttimes = Starttime.gettime ();
var arrs = B.split ("-");
var lktime = new Date (Arrs[0], arrs[1], arrs[2]);
var lktimes = Lktime.gettime ();
if (starttimes >= lktimes) {
Alert (' Start time is greater than departure time, please check ');
return false;
}
Else
return true;
}
(JS variable type allows us to do this:
var arr = a.split ("-");
var day = arr[0]+arr[1]+arr[2];
var now = new Date ();
var daynow = Now.getfullyear () +now.getmonth () +now.getday;
if (day <= daynow) {
Alert ("Date selection error");
}
)
js Time comparison (Yyyy-mm-dd hh:mi:ss)
function Comptime () {
var begintime = "2009-09-21 00:00:00";
var endtime = "2009-09-21 00:00:01";
var begintimes = begintime.substring (0). Split ('-');
var endtimes = endtime.substring (0). Split ('-');
BeginTime = begintimes[1] + '-' + begintimes[2] + '-' + begintimes[0] + ' + begintime.substring (10, 19);
Endtime = endtimes[1] + '-' + endtimes[2] + '-' + endtimes[0] + ' + endtime.substring (10, 19);
Alert (begintime + "AAA" + endtime);
Alert (Date.parse (Endtime));
Alert (Date.parse (begintime));
var a = (Date.parse (endtime)-Date.parse (BeginTime))/3600/1000;
if (a < 0) {
Alert ("Endtime small!");
else if (a > 0) {
Alert ("Endtime big!");
else if (a = = 0) {
Alert ("Equal time!");
} else {
Return ' exception '
}
}