class MyTimetask extends TimerTask{
public void run() {
System.out.println("闹钟响了");
}
}
class hello {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException, InterruptedException {
Timer t = new Timer();
t.schedule(new MyTimetask(), new Date(119, 1, 26, 16, 35, 30),1000);//设置时间为2019年一月26日16点35分30秒,并每隔一秒执行一次
}
}
运行结果: