How to count time - Programmers Heaven

Howdy, Stranger!

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


How to count time

sampath47sampath47 Posts: 5Member

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


  • 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() {
    timePassed = System.currentTimeMillis()-startTime;
    try {
    } 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;
  • LetifeRLetifeR Posts: 2Member
    duplicated post
Sign In or Register to comment.