# Countdown timer is not working

**URL:** <https://discourse.processing.org/t/countdown-timer-is-not-working/36761>\
**Category:** Processing.py\
**Created:** [May 7, 2022, 3:58pm UTC](https://discourse.processing.org/t/countdown-timer-is-not-working/36761 "2022-05-07T15:58:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snakey](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@snakey](https://discourse.processing.org/u/snakey)\
**Post date:** [May 7, 2022, 3:58pm UTC](https://discourse.processing.org/t/countdown-timer-is-not-working/36761/1 "2022-05-07T15:58:07Z")

</div>

[Original post] [Countdown timer in python](https://discourse.processing.org/t/countdown-timer-in-python/36243)

I’ve been using this timer in my game for a while, but I’ve just noticed a problem.  
The timer utilises `second()`, once the seconds on my clock go past 59 and turn to 0, the timer in my game adds 60 seconds to the countdown. How can I fix this? Thank you so much!

Code:

```auto
start = False

def setup():
    size(500, 500)
    
def draw():
    global timer
    background(0)
    if start:
        textSize(100)
        text(timer.remainingTime(), 220, 280)
    else:
        rect(200, 200, 100, 100)
    

class Timer:
    def __init__ (self, duration):
        self.duration = duration
        self.start_time = second()
    def remainingTime(self):
        return self.duration - (second() - self.start_time)
    
def mousePressed(): 
    global start, timer
    start = True
    timer = Timer(10)

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [May 7, 2022, 9:31pm UTC](https://discourse.processing.org/t/countdown-timer-is-not-working/36761/2 "2022-05-07T21:31:55Z")

</div>

Use [`millis()`](https://py.processing.org/reference/millis.html) instead. This returns the number of milliseconds since starting the sketch (not the current second from your computer clock) –

```python
class Timer:
    def __init__ (self, duration):
        self.duration = duration
        self.start_time = millis()/1000
    def remainingTime(self):
        return self.duration - (millis()/1000 - self.start_time)

```
