Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapp;
  7.  
  8. /**
  9. *
  10. * @author pw.gr2.5
  11. */
  12. public class Stopwatch {
  13.  
  14.  
  15. private long start;
  16.  
  17. public Stopwatch() {
  18. start = 0;
  19. }
  20.  
  21. public void start() {
  22. if(start == 0)
  23. start = System.currentTimeMillis();
  24. }
  25.  
  26. // return time (in seconds) since this object was created
  27. public double elapsedTime() {
  28. if(start == 0) { return 0; } //You need to start it first
  29.  
  30. long time = (long) ((System.currentTimeMillis() - start) / 1000.0);
  31. start = 0; // reset start to allow you to start it again later
  32. return time;
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement