日期:2014-05-18  浏览次数:20632 次

怎么用JS判断两个时间段跨度小于三个月啊?
var startDate = $("#startDate").val() ;
var endDate = $("#endDate").val() ;
if(startDate==null || endDate==null || startDate=="" || endDate==""){
  alert("起止时间不能为空");
  return ;
}

if(startDate>=endDate){
  alert("结束时间应大于开始时间") ;
  return ;
}

startDate 和endDate是从页面获取到的两个时间段,格式为yyyy-MM-dd hh:mm:ss ,怎么判断这两个时间段跨度小于三个月啊?
PS:就是小于三个月,不是小于90天或之类的。
js

------解决方案--------------------

var start  = new Date(startDate.replace(/-/g,"/")).getTime();
var end = new Date(endDate.replace(/-/g,"/")).getTime();
end - start  > n*24*60*60*1000 

3个月肯定要换算多少天,如果要精确,判断一下,如果starttime 的月份 如果是2月 则n=28or29+31+30
自己算 没有捷径