java比较日期,时间戳是啥
公共类测试{
privatefinalstringservervalue=' 2011-01-23-12.31.45 '; //Old should fail
privatefinalstringservervaluenew=' 2011-03-28-14.02.00 '; //New
privatesimpledateformatdateformat=newsimpledateformat (' yyyy-mm-DD-hh.mm.ss ' );
publicbooleanplusminustwomins (stringservervalue ) (
布尔within range=false;
Date now=Calendar.getInstance ().getTime );
Date serverDate=now;
try {
server date=date format.parse (服务器value;
}catch(parseexceptione ) {
e .打印任务跟踪(;
}
long millis=math.ABS (now.gettime (-server date.gettime ) );
//1000ms * 60s * 2m
if(Millis=(1000*60*2) ) ) )
withinRange=true;
}
返回范围;
}
publicstaticvoidmain (stringwsdxgargs ) {
Test test=new Test (;
boolean value=test.plusminustwomins (test.server value );
boolean value2=test.plusminustwomins (test.servervaluenew;
}