SimpleDateFormat dateFormater = new SimpleDateFormat("HHmm"); String date= dateFormater.format(new Date()); System.out.println(date); int time = Integer.parseInt(date); if(time>1600&&time<1700){ System.out.println("在时间段内"); }else{ System.out.println("不在这个时间段内"); }