Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapp;
- /**
- *
- * @author pw.gr2.5
- */
- public class Stopwatch {
- private long start;
- public Stopwatch() {
- start = 0;
- }
- public void start() {
- if(start == 0)
- start = System.currentTimeMillis();
- }
- // return time (in seconds) since this object was created
- public double elapsedTime() {
- if(start == 0) { return 0; } //You need to start it first
- long time = (long) ((System.currentTimeMillis() - start) / 1000.0);
- start = 0; // reset start to allow you to start it again later
- return time;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement