Chin
Chin

Reputation: 613

Java How to get the time when timer is stopped?

I'm currently referring to this link to create the timer for my program.

But I don't know how to get the time when timer is stopped.

I think System.getcurrentTimeMillis() cannot be used at this moment.

So, how can I get the current time when timer is stopped with the method mentioned?

EDIT :

I'm currently building a simple 4X4 memory game, and I have timer in my program, using the method from this link.

At the end of the game, I'll use a showMessageDialog to display the number of clicks and time used. However, I'm just able to display the clicks, which is the easiest part.

Based on the method from the link, I think I can use an easy way such as

JOptionPane.showMessageDialog( null, "Congratulations. \n You have win the game with " + click + " click(s) in " + hour + "hour(s) " + minute + " minute(s) " + second + " second(s).", "Win", 1);

Is there any better way of doing it?

Upvotes: 2

Views: 1072

Answers (1)

ControlAltDel
ControlAltDel

Reputation: 35011

You can use


Date d = new Date();
DateFormat df = new SimpleDateFormat("hh:mm:ss");
String dateStr = df.format(d);

Upvotes: 1

Related Questions