js比较两个日期的大小

function CompareDate(d1,d2)
{
  return ((new Date(d1.replace(/-/g,"\/"))) > (new Date(d2.replace(/-/g,"\/"))));
}
 
var current_time = "2007-2-2 7:30";
var stop_time = "2007-1-31 8:30";
alert(CompareDate(current_time,stop_time));

 弹出的值为true或者false

 

var curTime = new Date();
//2把字符串格式转换为日期类
var startTime = new Date(Date.parse(kc.begintime));
var endTime = new Date(Date.parse(kc.endtime));
 
//3进行比较
return (curTime>=startTime && curTime<=endTime);

 

posted @ 2017-05-04 14:32  黄金时代1.0  阅读(1168)  评论(0编辑  收藏  举报