例1,js日期比较(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('开始时间大于离开时间,请检查');
return false;
}
else
return true;
}
例2,js时间比较(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, 10).split('-');
var endtimes = endtime.substring(0, 10).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)); //(脚本学堂 www.jb200.com 编辑整理)
alert(date.parse(begintime));
var a = (date.parse(endtime) - date.parse(begintime)) / 3600 / 1000;
if (a < 0) {
alert("endtime小!");
} else if (a > 0) {
alert("endtime大!");
} else if (a == 0) {
alert("时间相等!");
} else {
return 'exception'
}
}
例3,js日期计算函数