if (f_now()>f_add_d(-1)) {
alert('今天比昨天的字符串大');
}
function f_now(){// 这是来至http://baishizhidao.com的代码
var myDate=new Date;
var year=myDate.getFullYear(); //获取当前年
var mon=myDate.getMonth()+1<10?"0"+(myDate.getMonth()+1):myDate.getMonth()+1; //获取当前月
var date=myDate.getDate()<10?"0"+myDate.getDate():myDate.getDate(); //获取当前日
var hour=myDate.getHours()<10?"0"+myDate.getHours():myDate.getHours();//获取当前时
var minute=myDate.getMinutes()<10?"0"+myDate.getMinutes():myDate.getMinutes();//获取当前分
var seconds=myDate.getSeconds()<10?"0"+myDate.getSeconds():myDate.getSeconds();//获取当前分
return year+"-"+mon+"-"+date+" "+hour+":"+minute+":"+seconds;
}
function f_date_time(mydatetime){//格式化日期
var myDate=new Date(mydatetime);
var year=myDate.getFullYear(); //获取当前年
var mon=myDate.getMonth()+1<10?"0"+(myDate.getMonth()+1):myDate.getMonth()+1; //获取当前月
var date=myDate.getDate()<10?"0"+myDate.getDate():myDate.getDate(); //获取当前日
var hour=myDate.getHours()<10?"0"+myDate.getHours():myDate.getHours();//获取当前时
var minute=myDate.getMinutes()<10?"0"+myDate.getMinutes():myDate.getMinutes();//获取当前分
var seconds=myDate.getSeconds()<10?"0"+myDate.getSeconds():myDate.getSeconds();//获取当前分
return year+"-"+mon+"-"+date+" "+hour+":"+minute+":"+seconds;
}
function f_add_d(n){
var nowDate=new Date();
return f_date_time(nowDate.setDate(nowDate.getDate()+n));
}
function f_add_m(n){
var nowDate=new Date();
return f_date_time(nowDate.setMonth(nowDate.getMonth()+n));
}
function f_add_y(n){
var nowDate=new Date();
return f_date_time(nowDate.setYear(nowDate.getFullYear()+n));
}