forum

Home / DeveloperSection / Forums / How to update Java timer every second?

How to update Java timer every second?

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

privatevoid 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.


Updated on 04-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By