Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active March 19, 2019 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/bdc1c92d394c586241b14cf937fcabb0 to your computer and use it in GitHub Desktop.
Save parzibyte/bdc1c92d394c586241b14cf937fcabb0 to your computer and use it in GitHub Desktop.
// No olvides importar las clases en la parte superior de tu archivo:
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
// Pon el código dentro de un método que se ejecute al inicio y una sola vez
DateTimeFormatter formateador = DateTimeFormatter.ofPattern("HH:mm:ss");
Runnable runnable = new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(500);
etiquetaReloj.setText(formateador.format(LocalDateTime.now()));
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Thread hilo = new Thread(runnable);
hilo.start();
// Aquí pon el código que iría normalmente, en caso de que exista
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment