import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class TimeCompare {
public static int Hour(Date time){
SimpleDateFormat st=new SimpleDateFormat("yyyyMMddHH");
return Integer.parseInt(st.format(time));
}
public static Date StringToDate(String s){
Date time=new Date();
SimpleDateFormat sd=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try{
time=sd.parse(s);
}
catch (ParseException e) {
System.out.println("输入的日期格式有误!");
}
return time;
}
public static void main(String[] args) {
String a="2012/01/01 18:08:20";
String b="2012/01/01 18:01:20";
String c="2012/01/02 01:01:01";
if(Hour(StringToDate(a))<=Hour(StringToDate(b))&&Hour(StringToDate(a))<Hour(StringToDate(c)))
System.out.println("成功");
else
System.out.println("失败");
}
}