我们需要转变2015-08-30两秒,然后利用PHP的秒数减少的
日期差异。然后我们可以增加判断。如果我们判断日期相等,那就简单多了。
例1,日期的差分
函数 功能better_time(strdatestart,strdateend){
var =strseparator ; / /日期分隔符
无功strdatearraystart;
Var strDateArrayEnd;
无功intday;
strdatearraystart = strdatestart.split(strseparator);
strdatearrayend = strdateend.split(strseparator);
无功strdates =新的日期(strdatearraystart { 0 } +/+ strdatearraystart { 1 } +/+ strdatearraystart { 2 } );
无功strdatee =新的日期(strdatearrayend { 0 } +/+ strdatearrayend { 1 } +/+ strdatearrayend { 2 } );
intday =(strdatee strdates)/(1000×3600×24);
返回intday;
}
例2
功能checktime(){
无功dateinp = $(# dateinp )瓦迩();
VaR的第一天= date.parse(dateinp.replace( / / g, / ));
无功nowdate =新的日期();
VaR中= nowdate.getfullyear()+/+(nowdate.getmonth()+ 1)+/+ nowdate.getdate();
var 2 = date.parse(中);
无功aparttime = day1-day2;
无功apartday = parseInt(aparttime /(1000 * 60 * 60 * 24));
如果(apartday = = 0){
警报(不能在同一天预约);
返回false;
}else if (apartDay 3) {
警报(约会的日期超出了范围);
返回false;
}
}
判决的日期相等。
VaR date1 =新的日期(2013-11-29 );
VAR把=新的日期(2013()11-29 );
console.log(date1。时间)(日期2。时间)(= =); / /真的
小心,你不写这个
VaR date1 =新的日期(2013-11-29 );
VaR date2 =新大()TE(2013-11-29 );
console.log(date1 = =日期2); / /假
这是
错误的,因为日期是新对象使用后的日期,那么对象不能与字符进行比较。