Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Simple Timer class

Featured Replies

public class Timer {
    
    private boolean running = false;
    
    private long startTime = 0;
    private long stopTime = 0;
    
    public void start() {
        this.startTime = System.currentTimeMillis();
        this.running = true;
    }
    
    public void stop() {
        this.stopTime = System.currentTimeMillis();
        this.running = false;
    }
    
    public long elapsed() {
        long elapsed;
        if(running)
            elapsed = (System.currentTimeMillis() - startTime);
        else
            elapsed = (stopTime - startTime);
        return elapsed;
    }
    
    public int getHourly(int number) {
        return (int) (number * 3600000.0D / elapsed());
    }
    
    public String getFormattedString() {
        long time = elapsed() / 1000;
        return String.format("%02d:%02d:%02d", time / 3600, (time % 3600) / 60, (time % 60));
    }
}

Example usage...

public static void main(String... a) throws InterruptedException {
        Timer time = new Timer();
        time.start();
        Thread.sleep(1000);
        System.out.println(time.getFormattedString());
    }

I'm afraid that this class is semantically incorrect ph34r.png. A 'Timer' class is supposed to be an object which counts down from a particular time interval. So, in this case, a proper class name would be 'Stopwatch' (i.e., measuring elapsed time by counting time upwards). Nonetheless, thanks for sharing smile.png .

Here is my Timer class:

public class Timer {

     private long period;
     private long startTime;

     public Timer(long period) {
          this.period = period;
          startTime = System.currentTimeMillis();
     }

     public boolean isRunning() {
          return getElapsed() < period;
     }

      public long getElapsed() {
           return System.currentTimeMillis() - startTime;
     }

     public long getRemaining() {
           return period - getElapsed();
     }

     public void reset() {
          startTime = System.currentTimeMillis();
     }

     public void stop() {
           period = 0;
     }

     public static String format(long ms) {
           long sec = ms / 1000L;
           return String.format("%02d:%02d:%02d",new Object[] { Long.valueOf(sec / 3600L),
           Long.valueOf((sec % 3600L) / 60L),Long.valueOf(sec % 60L) });
     }
}

 

Edited by H0ppy

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.