Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to count time

sampath47sampath47 Posts: 5Member
Hello,

I am writing a program. For that I need to include a functionality where I should get notified when the predetermined time is completed. For example if I set the time as 25 minutes I should be notified when 25 minutes are over.

Please tell me a way to do it

Comments

  • LetifeRLetifeR Posts: 2Member
    if you post your code i can have a better idea of how you need to use it.
    you can try something like this:

    [color=Blue]Thread t = new Thread(new Runnable() {
    long startTime = System.currentTimeMillis();
    private volatile boolean timeUp = false;
    final int END_TIME = 1;
    long timePassed;
    public void run() {
    while(!timeUp){
    timePassed = System.currentTimeMillis()-startTime;
    update(timePassed);
    try {
    Thread.sleep(100);
    } catch (InterruptedException e) {
    //you can handle the exception i you like
    }
    }
    [color=Blue]System.out.println("time up"); [/color]
    }
    private void update(long timePassed){
    if(timePassed >= END_TIME*60000) timeUp = true;
    }
    });
    t.start();[/color]
  • LetifeRLetifeR Posts: 2Member
    duplicated post
Sign In or Register to comment.