date日期比较

获取系统当前时间和xx时间做对比

public static void checkTime(){

//获取当前系统时间
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
String time=df.format(new Date());
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
//将获取到的当前时间转换为long格式
long longstr1 = Long.valueOf(time.replaceAll("[-\s:]",""));

//获取需要对比的时间
long longstr2 = Long.valueOf(classes.getRegistrationEndTime().replaceAll("[-\s:]",""));
//进行对比
if(longstr1>=longstr2){
System.out.println(longstr1+"longstr1");
System.out.println(longstr2+"longstr2");
//可根据需求执行操作
例: toSignUpService.updateByTime(classes.getRegistrationEndTime());
}


}

原文地址:https://www.cnblogs.com/luYing666/p/11589412.html