How to count time

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

  • 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]
  • duplicated post
Sign In or Register to comment.

Howdy, Stranger!

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

Categories

In this Discussion