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!


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

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.