# Help code \_ Climate Clock - Countdown events

**URL:** <https://discourse.processing.org/t/help-code-climate-clock-countdown-events/31070>\
**Category:** Coding Questions\
**Created:** [July 5, 2021, 1:59pm UTC](https://discourse.processing.org/t/help-code-climate-clock-countdown-events/31070 "2021-07-05T13:59:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HVK370](https://avatars.discourse-cdn.com/v4/letter/h/e95f7d/32.png) [@HVK370](https://discourse.processing.org/u/HVK370)\
**Post date:** [July 5, 2021, 1:59pm UTC](https://discourse.processing.org/t/help-code-climate-clock-countdown-events/31070/1 "2021-07-05T13:59:55Z")

</div>

Hello p5js community!  
This is my first code, sorry for that.  
the result should be YRS: Y Day: DDD hh: mm: ss  
such as [https://climateclock.world](https://climateclock.world)  
I wrote this code but the days calculation doesn’t work. can you help me ?

\</\>   
var years = year();  
var days = day();  
var hours = hour();  
var minutes = minute();  
var seconds = second();

if(seconds != prevSec) {  
prevSec = seconds;  
years = nf (2027 - years, 1,0);  
days = nf (days, 3,0);  
hours = nf(24 - hours, 2, 0);  
minutes = nf(60 - minutes, 2, 0);  
seconds = nf(60 - seconds, 2, 0);

```
Text(years + "-" + days + "-"+ hours + ":" + minutes + ":" + seconds);

```

}

\</\>

---

<div class="post-metadata">

**Author:** ![HVK370](https://avatars.discourse-cdn.com/v4/letter/h/e95f7d/32.png) [@HVK370](https://discourse.processing.org/u/HVK370)\
**Post date:** [July 5, 2021, 4:32pm UTC](https://discourse.processing.org/t/help-code-climate-clock-countdown-events/31070/3 "2021-07-05T16:32:13Z")

</div>

Resolved:

```auto
	var years = year();
  var hours = hour();
  var minutes = minute();
  var seconds = second();
	
	var now = new Date();
	var start = new Date(now.getFullYear(), 0, 0);
	var diff = now - start;
	var oneDay = 1000 * 60 * 60 * 24;
	var days = 366-Math.floor(diff / oneDay);

  if(seconds != prevSec) {
    prevSec = seconds;
		years = nf (2027 - years, 1,0);
		days = nf (days, 3,0);
    hours = nf(24 - hours, 2, 0);
    minutes = nf(60 - minutes, 2, 0);
    seconds = nf(60 - seconds, 2, 0);
	
    updateText(years + "-" + days + "-"+ hours + ":" + minutes + ":" + seconds);
  }

```
