Users Pricing

forum

Home Forums How to update Java timer every second? – MindStick

How to update Java timer every second?

Allen Scott 2900 04 Nov 2014
I want to grab the current date and time from the system which i can do with this code:

private void GetCurrentDateTimeActionPerformed(java.awt.event.ActionEvent evt)
{                                                  
     DateFormat dateandtime = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
     Date date = new Date();
     CurrentDateTime.setText(dateandtime.format(date));
}

Doing this is fine as it will grab he current date nad time no problem, however it is not dynamic as the time will not update unless the button is pressed again. So I was wondering how I could make this button more dynamic by updating the function every second to refresh the time.


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md