# Delta time / day

**URL:** https://discourse.processing.org/t/delta-time-day/9441
**Category:** Coding Questions
**Created:** [March 19, 2019, 1:43pm UTC](https://discourse.processing.org/t/delta-time-day/9441 "2019-03-19T13:43:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![NAA](https://avatars.discourse-cdn.com/v4/letter/n/c4cdca/32.png) [@NAA](https://discourse.processing.org/u/NAA)
#### Post date: [March 19, 2019, 1:43pm UTC](https://discourse.processing.org/t/delta-time-day/9441/1 "2019-03-19T13:43:38Z")

</div>

Hey everyone!  
Couple of newbie question here, I’ve look trough the forum but I didn’t find what I was looking for.  
I’m writing a simple countdown for a specific day.  
Question 1:  
Why processing doesn’t update the image? It doesn’t update the value in the texts.

Question 2:  
I would have to countdown to a specific day (1 of June, 152 day of the year) what’s the best way to calculate the day of the year everyday? (_int e_ in the sketch).

Thank you!

```auto
PFont font;
int a = day();          
int b = (24 - hour());        
int c = (60 - minute());
int d = (152); //1 June start day
int e = (78); //19 march 

void setup()
{
  size(1920, 1080);
  font = createFont("ARIAL", 1000);
  background(52, 152, 219);
  fill(0);
  frameRate(1);
}

void draw()
{
    background(52, 152, 219);
    textSize(100);
    text("COUNTDOWN TO UEFA UNDER21:", width/12,height/5);
    textSize(200);
    text((d - e)+" giorni ", width/6,height/2);
    textSize(200);
    text(b+" ore ", width/6,height/1.4);
    textSize(200);
    text(c+" minuti", width/6,height/1.1);
    println(second());
}

```

---

<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: [March 19, 2019, 2:11pm UTC](https://discourse.processing.org/t/delta-time-day/9441/2 "2019-03-19T14:11:05Z")

</div>

you set the variables up like constants,  
for update ( every draw loop ) try:

```auto
PFont font;
int a, b, c, d, e;

void update() {
  a = day();          
  b = (24 - hour());        
  c = (60 - minute());
  d = (152); //1 June start day
  e = (78); //19 march
}

void setup()
{
  size(192, 108);
  font = createFont("ARIAL", 1000);
  background(52, 152, 219);
  fill(0);
  frameRate(1);
}

void draw()
{
  background(52, 152, 219);
  update();
  textSize(10);
  text("COUNTDOWN TO UEFA UNDER21:", width/12, height/5);
  textSize(20);
  text((d - e)+" giorni ", width/6, height/2);
  textSize(20);
  text(b+" ore ", width/6, height/1.4);
  textSize(20);
  text(c+" minuti", width/6, height/1.1);
  println(second());
}

```

---

<div class="post-metadata">

### Author: ![NAA](https://avatars.discourse-cdn.com/v4/letter/n/c4cdca/32.png) [@NAA](https://discourse.processing.org/u/NAA)
#### Post date: [March 19, 2019, 2:37pm UTC](https://discourse.processing.org/t/delta-time-day/9441/3 "2019-03-19T14:37:42Z")

</div>

It worked!  
It was great to learn the difference constants and variables within a sketch!  
Thanks a lot!

---

<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: [March 19, 2019, 2:49pm UTC](https://discourse.processing.org/t/delta-time-day/9441/4 "2019-03-19T14:49:14Z")

</div>

> [@NAA](#):
>
> Question 2:  
> I would have to countdown to a specific day (1 of June, 152 day of the year) what’s the best way to calculate the day of the year everyday? ( _int e_ in the sketch).

there is a long way… day EPOCH …

[SimpleDateFormat conversion - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/comment/41312/#Comment_41312) ,  
might help

i try this:

```auto
import java.util.*;

Calendar c = new GregorianCalendar();
Date countTo;
Date today;
long diff, diff_sec, diff_min, diff_hou, diff_day;

void update() {
  c.set(Calendar.YEAR, 2019);
  c.set(Calendar.MONTH, 6); // 6 = june
  c.set(Calendar.DAY_OF_MONTH, 1); // 2019-06-01
  countTo = c.getTime();
  today = new Date();
  diff = countTo.getTime() - today.getTime();
  diff_sec = diff / (1000L); // convert to sec 
  diff_min = diff / (1000L*60L); // convert to min
  diff_hou = diff / (1000L*60L*60L); // convert to hour
  diff_day = diff / (1000L*60L*60L*24L); // convert to days!
  println("days "+diff_day+" or hours "+diff_hou+" or minutes "+diff_min+" or seconds "+diff_sec);
}

void setup() {
  frameRate(1);
}
void draw() {
  update();
}

```

prints:

> days 103 or hours 2495 or minutes 149759 or seconds 8985597  
> days 103 or hours 2495 or minutes 149759 or seconds 8985596  
> days 103 or hours 2495 or minutes 149759 or seconds 8985595

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [March 20, 2019, 7:15am UTC](https://discourse.processing.org/t/delta-time-day/9441/5 "2019-03-20T07:15:02Z")

</div>

You can also check examples related to `java.time.LocalDateTime` if you what to explore other options. Because Processing is Java, you can always use any previously implemented solution in that language.

Kf

---

<div class="post-metadata">

### Author: ![NAA](https://avatars.discourse-cdn.com/v4/letter/n/c4cdca/32.png) [@NAA](https://discourse.processing.org/u/NAA)
#### Post date: [March 20, 2019, 8:50pm UTC](https://discourse.processing.org/t/delta-time-day/9441/6 "2019-03-20T20:50:31Z")

</div>

Thank you all!  
So, I’ve solved in an easier and more “dumb” way.  
-I take the value from “month ()”  
-I use the “if” to associate the month to the number of the days present in that month e.s for Jannuary (1=31).  
-Then I do a simple sum.  
I’ll post the complete sketch asap.

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [March 21, 2019, 5:31am UTC](https://discourse.processing.org/t/delta-time-day/9441/7 "2019-03-21T05:31:45Z")

</div>

If that approach works for you, go for it. I recommend you also try using an available library. This will give you the opportunity to read documentation and it will open the challenge to implement it in your own code. The nice thing about libraries is that it will handle oddities like leap years. With minor adjustments, you can also adjust your code to a time zone, if you were to include time information.

Kf
