If you just want to create a timer, you can create a thread that will execute every second in an infinite loop
public class SystemTime extends Thread {
@Override
public void run(){
while (true){
String time = new SimpleDateFormat("HH:MM:ss").format(Calendar.getInstance().getTime());
System.out.println(time);
try{
Thread.sleep(1000);
} catch (InterruptedException ie){
return;
}
}
}
}
source
share