private void timecompare() {
String btime=borrow_time.getText().toString();
String rtime="2017.07.30";
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat dateFormat1=new SimpleDateFormat("yyyy.MM.dd");
try {
Date date1=dateFormat.parse(btime);
Date date2=dateFormat1.parse(rtime);
Log.d("TAG","borrow:"+date1);
Log.d("TAG","rtime"+date2);
if (date1.getTime()>date2.getTime()){
finish();
}
} catch (ParseException e) {
e.printStackTrace();
}
这是两个时间的比较大小,第一个数大就退出程序,后面大家就举一反三吧