2

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?

Community
  • 1
  • 1
Chin
  • 593
  • 4
  • 15
  • 36
  • What makes you think that `System.getCurrentTimeMillis()` cannot be used? Since that's the crux of your problem, you need to give some justification for that statement (which initially seems to be just wrong, by the way). – Andrzej Doyle May 15 '12 at 15:34
  • I not sure I'm correct or not, `System.getcurrentTimeMillis()` return value in `milliseconds`, and the [method](http://stackoverflow.com/questions/5745745/creating-a-count-up-timer-to-break-when-puzzle-is-solved-java) is I'm referring to is in the format of `HH:MM:SS`. – Chin May 15 '12 at 15:37
  • take a look at SimpleDateFormat – ControlAltDel May 15 '12 at 15:46
  • Hmm... My program is running a timer that in `HH:MM:SS` format, but when I stop the `timer`, I want to get the current time showed by the `timer`. – Chin May 15 '12 at 15:58

1 Answers1

1

You can use


Date d = new Date();
DateFormat df = new SimpleDateFormat("hh:mm:ss");
String dateStr = df.format(d);
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80