I have already written a 60 seconds countdown timer but I would like to transform this to have a minutes and seconds timer like mm:ss
.
Can I rearrange this existing code to get that ?
Timer timer = new Timer();
TimerTask task = new TimerTask() {
int i = 60;
public void run(){
if (i >= 0) {
lab3.setText("Timer " + i--);
}
}
};
timer.scheduleAtFixedRate(task, 0, 1000);
You need to display remaining number of second i
in format mimutes:seconds
format. If you assume that there are always 60 seconds in a minute:
String time = String.format("%02d:%02d", i / 60, i % 60);
System.out.println(time);