public class DateTest {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd",
Locale.CHINA);
try {
String old = "2018-11-10";
Date oldDate = sdf.parse(old);
// 当前时间
Date newOld = new Date();
newOld = sdf.parse(sdf.format(newOld));
// flag,等于0日期相等,大于0表示在当前时间之后,小于0在当前时间之前
int flag = oldDate.compareTo(newOld);
} catch (ParseException e) {
e.printStackTrace();
}
}
}