1、比较日期大小
function dateCompare(date1,date2){
date1 = date1.replace(/\-/gi,"/");
date2 = date2.replace(/\-/gi,"/");
var time1 = new Date(date1).getTime();
var time2 = new Date(date2).getTime();
if(time1 > time2){
return 1;
}else if(time1 == time2){
return 2;
}else{
return 3;
}
}
alert(dateCompare("2011-06-27","2011-06-28"));
2、当前日期加1
function getNextDay(d){
d = new Date(d);
d = d.getTime() + 1000*60*60*24;
d = new Date(d);
//return d;
//格式化
return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
}
alert(getNextDay("2014-06-24"))
3、字符串转换成date类型
var str ='2012-08-12 23:13:15';
str = str.replace(/-/g,"/");
var date = new Date(str );