Jump to content

How to keep track of script time


Recommended Posts

Posted
public class Timer
{
  private final long start;
  private final long period;
  private long end;
  
  public Timer(long period)
  {
    this.period = period;
    this.start = System.currentTimeMillis();
    this.end = (this.start + period);
  }
  
  public long getElapsed()
  {
    return System.currentTimeMillis() - this.start;
  }
  
  public long getRemaining()
  {
    if (isRunning()) {
      return this.end - System.currentTimeMillis();
    }
    return 0L;
  }
  
  public boolean isRunning()
  {
    return System.currentTimeMillis() < this.end;
  }
  
  public void reset()
  {
    this.end = (System.currentTimeMillis() + this.period);
  }
  
  public long setEndIn(long ms)
  {
    this.end = (System.currentTimeMillis() + ms);
    return this.end;
  }
  
  public String toElapsedString()
  {
    return Time.format(getElapsed());
  }
  
  public String toRemainingString()
  {
    return Time.format(getRemaining());
  }
}

 

  • Like 1
Posted
3 hours ago, Chris said:

public class Timer
{
  private final long start;
  private final long period;
  private long end;
  
  public Timer(long period)
  {
    this.period = period;
    this.start = System.currentTimeMillis();
    this.end = (this.start + period);
  }
  
  public long getElapsed()
  {
    return System.currentTimeMillis() - this.start;
  }
  
  public long getRemaining()
  {
    if (isRunning()) {
      return this.end - System.currentTimeMillis();
    }
    return 0L;
  }
  
  public boolean isRunning()
  {
    return System.currentTimeMillis() < this.end;
  }
  
  public void reset()
  {
    this.end = (System.currentTimeMillis() + this.period);
  }
  
  public long setEndIn(long ms)
  {
    this.end = (System.currentTimeMillis() + ms);
    return this.end;
  }
  
  public String toElapsedString()
  {
    return Time.format(getElapsed());
  }
  
  public String toRemainingString()
  {
    return Time.format(getRemaining());
  }
}

 

ahh i see. Thanks man appreciate it

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...