1、日期参数格式:yyyy-mm-dd

// a: 日期a, b: 日期b, flag: 返回的结果
  function duibi(a, b,flag) {
var arr = a.split("-");
var starttime = new Date(arr[0], arr[1], arr[2]);
var starttimes = starttime.getTime();
var arrs = b.split("-");
var endTime = new Date(arrs[0], arrs[1], arrs[2]);
var endTimes = endTime.getTime();
// 进行日期比较
if (endTimes >= starttimes) {
flag = "true";
return flag;
}else{
flag = "false";
return flag;
}
  }

  

2、日期格式: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));
// 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'
}
 }

  

04-13 11:34