Package alarm;
Import Java.text.SimpleDateFormat;
Import Java.time.format.FormatStyle;
Import Java.util.Date;
Import Java.util.Timer;
Import Java.util.TimerTask;
Import Javax.xml.ws.Response;
public class Testtimerwu {
public static void Main (string[] args) {
TimerTask task = new TimerTask () {
@Override
public void Run () {
TODO auto-generated method stubs
SimpleDateFormat df = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String ss= Df.format (New Date ());
String Shifen = ss.substring (one, All). ToString ();
System.out.println (Shifen);
if (("21:56"). Equals (Shifen)) {
System.out.println ("Time Is up");
}else{
System.out.println ("The time has not arrived");
}
}
};
Timer timer=new timer ();
Timer.schedule (task, 0,1000);//indicates that the above thread is started every 5 seconds
}
}
Test class
Package alarm;
public class Test {
public static void Main (string[] args) throws Interruptedexception {
Testtimerwu.main (args);
}
}
Threads Monitor system time every 5 seconds