Jump to content

How to keep track of script time


Tylersbored

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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