# Countdown d, h, min, sec and ms?

**URL:** <https://discourse.processing.org/t/countdown-d-h-min-sec-and-ms/18145>\
**Category:** Coding Questions\
**Created:** [February 26, 2020, 3:56pm UTC](https://discourse.processing.org/t/countdown-d-h-min-sec-and-ms/18145 "2020-02-26T15:56:30Z")\
**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:** [February 27, 2020, 2:20am UTC](https://discourse.processing.org/t/countdown-d-h-min-sec-and-ms/18145/4 "2020-02-27T02:20:01Z")

</div>

Hello @Teljemo,

See my post:  
[Difference between two times (measuring time)](https://discourse.processing.org/t/difference-between-two-times-measuring-time/15728/4)

> **[Java.lang.System.currentTimeMillis() Method](https://www.tutorialspoint.com/java/lang/system_currenttimemillis.htm)**
>
> Java lang System currentTimeMillis() Method - The java.lang.System.currentTimeMillis() method returns the current time in milliseconds.The unit of time of the return value is a millisecond, the granularity of the value depends on the underlying...

states:

> **java.lang.System.currentTimeMillis()** returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC(coordinated universal time).

I used June 1, 2020 as my target date:  
[Days between Dates](https://www.timeanddate.com/date/durationresult.html?m1=1&d1=1&y1=1970&m2=6&d2=1&y2=2020)

Some code I wrote quickly using System.currentTimeMillis():

```auto
// Time Elapsed using System.currentTimeMillis()
// v1.0.0
// GLV 2020-02-26

import java.time.*;

long UTC = 5*60*60; //UTC adjustment

//Target time (in seconds) was extracted from here:
//https://www.timeanddate.com/date/durationresult.html?m1=1&d1=1&y1=1970&m2=6&d2=1&y2=2020
// This could be coded if you are so inclined.

//-60*60 was DST adjustment
long targetTime = 1590969600 + UTC -1*60*60; //2020-06-01

void setup() 
	{
  size(100, 100);
	}

void draw() 
	{
  background(0);  
  
  long timeRem = targetTime - System.currentTimeMillis()/1000;
  
  long days = timeRem/(60*60*24);
  long hrs = timeRem/(60*60);
  long mins = timeRem/(60);
  long secs = timeRem;
  long ms = 1000 - (secs*1000 - (targetTime*1000 - System.currentTimeMillis()));
  
  println(days + ":" + (hrs - days*24) + ":" + (mins - hrs*60) + ":" + (secs - mins*60) + ":" + ms);  
	}

```

My code above seems to be in sync with:

> **[Countdown Timer](https://www.timeanddate.com/countdown/generic?iso=20200601T00&p0=1181&font=cursive)**
>
> Counting time since Jun 1, 2020. Showing days, hours, minutes and seconds counting up

With the default frameRate of 60 fps you will only be updating in 16 ms steps.

At present it only prints to console.

This was just an exercise for me and can definitely be refined.

Update:

I added a few lines to display on canvas:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/58420069d7d5f9af61f2a25997d860f0afcd3f6f.png)

I used the formatting (@Chrisir also borrowed) from my code (linked above).  
It should be easy to integrate into your code:  
`String timeString = ( nf(int(days), 3) + ':' + nf(int(hrs - days*24), 2) + ':' + nf(int(mins - hrs*60)) + ':' + nf(int(secs - mins*60), 2) + ':' + nf(int(ms), 3) );`

`:)`

---

_[View the full topic](https://discourse.processing.org/t/countdown-d-h-min-sec-and-ms/18145)._
