时间比较早晚java
package demo;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class TimeCompare {
public static void main(String[] args) {
String filetime = "2016-10-20";
try {
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd",Locale.CHINA);
Date fileTime = s.parse(filetime);
Date todayDate = new Date();
String todayDay = s.format(todayDate);
Date todayTime = s.parse(todayDay);
if(fileTime.before(todayTime)){
System.out.println("传过来的时间比今天早");
}else{
System.out.println("传过来的时间比今天晚");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}