I have a class in which I want to get the current time of the pc but it is not updated, it is always the same time, any solution?
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Hora extends Thread{
Calendar c = new GregorianCalendar();
int hora, minutos, segundos;
@Override
public void run() {
while(true){
setHora();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Logger.getLogger(Hora.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void setHora() {
String h;
hora = c.get(Calendar.HOUR_OF_DAY);
minutos = c.get(Calendar.MINUTE);
segundos = c.get(Calendar.SECOND);
h = hora + ":" + minutos + ":" + segundos;
System.out.println(h);
}
}