SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
//时分秒
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int second = cal.get(Calendar.SECOND);
String sBuffer = hour + ":" + minute + ":" + second;
Date dt1 = formatter.parse("00:00:00");//将字符串转换为date类型
Date dt2 = formatter.parse("07:00:00");//将字符串转换为date类型
Date dt3 = formatter.parse("24:00:00");
// 系统当前时分秒
Date dt4 = formatter.parse(sBuffer);
if(dt1.getTime() < dt4.getTime() && dt4.getTime() < dt2.getTime()) {
System.out.println("0~7点:来早了~");
}
if(dt2.getTime() < dt4.getTime() && dt4.getTime() < dt3.getTime()) {//比较时间大小,如果dt1大于dt2
System.out.println("10~24点:来晚了~");
}