# How to make a timer in Processing?

**URL:** <https://discourse.processing.org/t/how-to-make-a-timer-in-processing/20481>\
**Category:** Coding Questions\
**Created:** [May 4, 2020, 11:08pm UTC](https://discourse.processing.org/t/how-to-make-a-timer-in-processing/20481 "2020-05-04T23:08:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cybernet](https://avatars.discourse-cdn.com/v4/letter/c/54ee81/32.png) [@Cybernet](https://discourse.processing.org/u/Cybernet)\
**Post date:** [May 4, 2020, 11:08pm UTC](https://discourse.processing.org/t/how-to-make-a-timer-in-processing/20481/1 "2020-05-04T23:08:25Z")

</div>

So I know this is a really simple question, but I can’t figure out how to do it!

So I have this code:

```auto
void draw()
{
    if (startGame)
        // do stuff

   if (lose)
       DisplayTimer();
}

void mousePressed()
{
    startGame = true;
}

```

So as soon as the person pressed the mouse, it starts the timer. And when the person loses the game, the timer stops. Now I considered using `millis()` however I can’t figure out how it make it start when the game starts.

Can anyone help me? Thanks

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [May 4, 2020, 11:15pm UTC](https://discourse.processing.org/t/how-to-make-a-timer-in-processing/20481/2 "2020-05-04T23:15:00Z")

</div>

> [@Cybernet](#):
>
> Now I considered using `millis()` however I can’t figure out how it make it start when the game starts.

millis() started counting as soon as you started your sketch.

> **[millis() / Reference](https://processing.org/reference/millis_.html)**
>
> Returns the number of milliseconds (thousandths of a second) since starting the sketch. This information is often used for timing animation sequences.

An example here:

> [@Some questions about millis()](https://discourse.processing.org/t/some-questions-about-millis/19541/3):
>
> Hello, You can’t reset millis(). You can start a time elapsed counter that counts from the time started. A simple example: int timeStart; int timeElapsed; void setup() { timeStart = millis(); } void draw() { timeElapsed = millis() - timeStart; println(timeElapsed); } void keyPressed() { timeStart = millis(); //Resets time elapsed counter }slight_smile Other millis() examples here:

`:)`
