简体   繁体   English

Java如何获取计时器停止的时间?

[英]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. 但是我不知道如何获得timer停止的时间。

I think System.getcurrentTimeMillis() cannot be used at this moment. 我认为System.getcurrentTimeMillis()目前无法使用。

So, how can I get the current time when timer is stopped with the method mentioned? 那么,使用上述方法停止timer ,如何获取当前时间?

EDIT : 编辑:

I'm currently building a simple 4X4 memory game, and I have timer in my program, using the method from this link . 我目前正在构建一个简单的4X4内存游戏,并且使用此link中的方法在我的程序中包含计时器。

At the end of the game, I'll use a showMessageDialog to display the number of clicks and time used. 在游戏结束时,我将使用showMessageDialog来显示点击次数和使用时间。 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? 有什么更好的方法吗?

You can use 您可以使用


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM