简体   繁体   中英

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

Because when you are trying to update an UI from child thread it will thrown an exception.

Make use of System.currentTimemilli() api to calculate the time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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