# Clock, reset hour and new day statement

**URL:** https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837
**Category:** Coding Questions
**Created:** [September 6, 2019, 7:46am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837 "2019-09-06T07:46:25Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![vincentstrebelle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vincentstrebelle/32/6963_2.png) [@vincentstrebelle](https://discourse.processing.org/u/vincentstrebelle)
#### Post date: [September 6, 2019, 7:46am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/1 "2019-09-06T07:46:25Z")

</div>

Hi, i made a very basic clock and i have two questions.

1: I wonder how can i reset the hours. Like when it past 24 it restart to 0.  
2: How can i make a statement when a new day start. Can i use a boolean ?

```auto
void setup(){
  size(200,40);
}

int time = 0;
int seconds;
int minutes;
int hour;
int day;

void draw(){
  background(0);
  clockTick();
  text("minutes " + minutes,10,10);
  text("hour " + hour,10,20);
  text("day " + day,10,30);
}

void clockTick(){
  time = millis();
  seconds = (int) (time/1000)*7200;
  minutes = seconds/60;
  hour = minutes/60;
  day = hour/24;
}

```

Thanks for your help.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [September 6, 2019, 8:17am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/2 "2019-09-06T08:17:11Z")

</div>

-a- you not need to calculate:

```auto
void setup(){
  size(200,40);
  textSize(15);
}
void draw() {
  background(0,0,80);
  text(year()+"/"+month()+"/"+day()+" "+hour()+":"+minute()+":"+second(),10,25);
}

```

-b- millis() not give the clock time ,  
it give the milli seconds since sketch start.

---

<div class="post-metadata">

### Author: ![vincentstrebelle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vincentstrebelle/32/6963_2.png) [@vincentstrebelle](https://discourse.processing.org/u/vincentstrebelle)
#### Post date: [September 6, 2019, 8:23am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/3 "2019-09-06T08:23:52Z")

</div>

Hi, That’s not what i mean,

> [@kll](#):
>
> it give the milli seconds since sketch start.

I know it’s what i want, an “in game” clock

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [September 6, 2019, 8:30am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/4 "2019-09-06T08:30:48Z")

</div>

```auto
int time = 0;
int seconds;
int minutes;
int hour;
int day;

void draw_time(){
  background(0);
  clockTick();
  text(" s " + seconds+" m " + minutes+" h " + hour+" d " + day,10,30);
}

void clockTick(){
  time = millis();
  seconds = (int) (time/1000);//????*7200;
  minutes = seconds/60;
  hour = minutes/60;
  day = hour/24;
  // repair
  hour -= day*24;
  minutes -= day*24*60 +hour*60;
  seconds -= day*24*60*60 +hour*60*60 + minutes*60;
}

```

but that is the primitive way… pls find modulo % !!  
also check if ‘time’ can be INT or should be LONG

---

<div class="post-metadata">

### Author: ![vincentstrebelle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vincentstrebelle/32/6963_2.png) [@vincentstrebelle](https://discourse.processing.org/u/vincentstrebelle)
#### Post date: [September 6, 2019, 8:59am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/5 "2019-09-06T08:59:06Z")

</div>

Thanks i will check modulo.  
How can i make a statement when a new day start ?  
Like when day increment by one, i have a text say “a new day start”

---

<div class="post-metadata">

### Author: ![vincentstrebelle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/vincentstrebelle/32/6963_2.png) [@vincentstrebelle](https://discourse.processing.org/u/vincentstrebelle)
#### Post date: [September 6, 2019, 9:24am UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/6 "2019-09-06T09:24:19Z")

</div>

i found a way, i pretty sure its not the best but it work.

```auto
  if(hour <= 1){
    text("new day",10,40);
  }

```

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [September 6, 2019, 7:27pm UTC](https://discourse.processing.org/t/clock-reset-hour-and-new-day-statement/13837/7 "2019-09-06T19:27:37Z")

</div>

> [@vincentstrebelle](#):
>
> Like when it past 24 it restart to 0

Modulo wraps around to zero. [% (modulo) / Reference / Processing.org](https://processing.org/reference/modulo.html)

So if you are counting:

| x | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| x%8 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 | 1 | 2 |
| x%5 | 0 | 1 | 2 | 3 | 4 | 0 | 1 | 2 | 3 | 4 | 0 |
| x%3 | 0 | 1 | 2 | 0 | 1 | 2 | 0 | 1 | 2 | 0 | 1 |
| x%2 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 |

In your case, if you want to count from 0-23 over and over, then:

`h = (h+1)%24`
