# Need assistance with timing! \[millis()\]

**URL:** <https://discourse.processing.org/t/need-assistance-with-timing-millis/18854>\
**Category:** Coding Questions\
**Created:** [March 20, 2020, 10:57pm UTC](https://discourse.processing.org/t/need-assistance-with-timing-millis/18854 "2020-03-20T22:57:23Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [March 21, 2020, 12:00am UTC](https://discourse.processing.org/t/need-assistance-with-timing-millis/18854/4 "2020-03-21T00:00:16Z")

</div>

I provided a simple example:

```auto
int whattimeisitnow;
int whattimeisitatstartofstopwatch;
int timepassedtoresetstopwatch = 1000;

//setup runs once
void setup()
  {
  whattimeisitatstartofstopwatch = millis();  
  }

//draw loops 60 frames per sec  
void draw()
  {
  whattimeisitnow = millis();
  if (whattimeisitnow > whattimeisitatstartofstopwatch + timepassedtoresetstopwatch)  
    {
    println("1000 ms have passed!");
    whattimeisitatstartofstopwatch = millis(); //reset stopwatch and start over
    }
  }

```

This is a very basic timer that is very common; I just added descriptive variable names.

I would like you to explain to me how it works and then try writing it from scratch.  
I do this often (code from scratch) as an exercise to work my brain.

You can also add println() statements to see what is going on with code.  
Keep in mind that millis() is constantly updating in the background with the passage of time and the variables will update.

[https://processing.org/reference/millis\_.html](https://processing.org/reference/millis_.html)

`:)`

---

_[View the full topic](https://discourse.processing.org/t/need-assistance-with-timing-millis/18854)._
