简体   繁体   English

如何在Java中测量两次按钮单击之间的时间

[英]how to measure time between two button clicks in java

I am doing an employee clocking system and payroll processing. 我正在做一个员工计时系统和工资单处理。 I am having problems in clocking the employees. 我在给员工计时时遇到问题。 I have managed to create a clock but the problem is that I want to start the clock when a 'clock in' button is pressed and stop the clock when a 'clock out' button is pressed and store the total time worked in a database. 我设法创建了一个时钟,但是问题是我想在按下“时钟输入”按钮时启动时钟,而在按下“时钟输出”按钮时停止时钟,并将工作的总时间存储在数据库中。

long startTime = System.currentTimeMillis();
yourAction();
long endTime = System.currentTimeMillis();
long time = endTime - startTime;

Draw a UI for a clock. 绘制时钟的UI。 When you start click a button start a handler to start update the UI of a clock and do the same thing for another stop button also. 当您开始单击按钮时,启动处理程序以开始更新时钟的UI,并对另一个停止按钮执行相同的操作。

Because when you are trying to update an UI from child thread it will thrown an exception. 因为当您尝试从子线程更新UI时,它将引发异常。

Make use of System.currentTimemilli() api to calculate the time. 利用System.currentTimemilli()api计算时间。

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

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