This site requires JavaScript, please enable it in your browser!
Greenfoot back
Randalini
Randalini wrote ...

2017/5/24

Day Timer

Randalini Randalini

2017/5/24

#
I need a timer which counts in 10 Min steps from 0:00 to 23:50 and counts the number of the days every time the timer gets to 0:00. Pls dont send me links. I cant open them
danpost danpost

2017/5/24

#
All you need is one long type field and one int counter. The counter is incremented every 10 minutes and the other is to hold the time when the counter is to be incremented next:
private long incTime = System.currentTimeMillis()+600000;
private int counter;

public void act()
{
    if (System.currentTimeMillis() >= incTime) bumpCounter();
}

private void bumpCounter()
{
    incTime += 600000;
    counter++;
    updateDisplay();
}

private void updateDisplay()
{
    int count = counter;
    int days = count/144;
    count = count%144;
    int hrs = count/6;
    int mins = (count%6)*10;
    // etc. (use 'days' 'hrs' and 'mins' to display time)
}
You need to login to post a reply.