# Timer with specific format

**URL:** <https://discourse.processing.org/t/timer-with-specific-format/6864>\
**Category:** Coding Questions\
**Created:** [December 24, 2018, 1:40am UTC](https://discourse.processing.org/t/timer-with-specific-format/6864 "2018-12-24T01:40:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelPCgamer](https://avatars.discourse-cdn.com/v4/letter/m/51bf81/32.png) [@MichaelPCgamer](https://discourse.processing.org/u/MichaelPCgamer)\
**Post date:** [December 24, 2018, 1:40am UTC](https://discourse.processing.org/t/timer-with-specific-format/6864/1 "2018-12-24T01:40:28Z")

</div>

```auto
int milli;
int hours;
int minutes; 
int seconds; 

void setup () {
  size(600, 400);
}

void draw() {
  background(0);
  milli = millis();
  seconds = milli / 1000;
  minutes = seconds / 60;
  hours = minutes / 60;
  text("Time = " + hours + ":" + minutes + ":" + seconds + ":" + milli, 10, 10);

  //This text shows every number of millis, seconds, and minutes as if their independant numbers that don't reset to 0. 
  //aka don't loop around every particular number. millis should go to 999 then to 0, and repeat.  
  //Seconds should be based on every 1000 millis, and zero back to 0 at 60000. same for minutes.  

  //My theory is to create multiple functions which return a "looping" of each variable from 0 to it's own respective highest num.
}

```

//millis() = 999… “Time = 00:00:00:999”

//Formatting it a second issue I can deal with later.

//while millis() \< 999, “Time = 00:00:00:millis()”  
//While (millis() \>= 1,000 && millis() \<= 9,999), “Time = 00:00:0sec:millis()”  
//While (millis() \>= 10,000 && millis() \<= 59,999), “Time = 00:00:sec:millis()”  
//While (millis() \>= 60,000 && millis() \<= 69,999), “Time = 00:0min:0sec:millis()”  
//While (millis() \>= 70,000 && millis() \<= 599,999), “Time = 00:0min:sec:millis()”  
//While (millis() \>= 600,000 && millis() \<= 609,999), “Time = 00:min:0sec:millis()”

//Any instance of 0min or 0sec means that the 0 doesnt normally go there if num is \< 10, it’ll look like 00:3:00 instead of 00:03:00 like a normal timer.

//123456 … millis = 999, leaving 123 as seconds. 120 is a multiple of 60, making min = 2. 3 sec left over so proper format is 00:02:03:456.  
//2784624 … millis = 624. want to precisely measure every instance of hour, min, sec to allow 00:00:00:000 format to apply.  
//If number goes beyond 24 hours then it’ll go into days then other extensions of time. RN I’m only worried about up til 10 hours.

---

<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:** [December 24, 2018, 1:48am UTC](https://discourse.processing.org/t/timer-with-specific-format/6864/2 "2018-12-24T01:48:32Z")

</div>

are you aware of:

```auto
text("Time: "+year()+"/"+month()+"/"+day()+"_"+hour()+":"+minute()+":"+second(), width-160, 20);

```

like in

```auto
void setup() {
  size(300, 300);
}

void draw() {
  background(200,200,0);
  fill(0);
  text("Time: "+year()+"/"+month()+"/"+day()+"_"+hour()+":"+minute()+":"+second(), width-160, 20);
}

```

still if you want to know what math you would need :

```auto
int milli;
int hours;
int minutes; 
int seconds; 
int days;

void setup () {
  size(600, 400);
}

void draw() {
  background(0);
  get_time();
  text("Time = " + nf(days,3) + "_"+ nf(hours,2) + ":" + nf(minutes,2) + ":" + nf(seconds,2) + ":" + nf(milli,3), 10, 10);
}

void get_time() {
  milli = millis();
  seconds = milli / 1000;
  minutes = seconds / 60;
  hours = minutes / 60;
  days = hours / 24;
 
  //This text shows every number of millis, seconds, and minutes as if their independant numbers that don't reset to 0. 
  //aka don't loop around every particular number. millis should go to 999 then to 0, and repeat.  
  //Seconds should be based on every 1000 millis, and zero back to 0 at 60000. same for minutes.  

  //My theory is to create multiple functions which return a "looping" of each variable from 0 to it's own respective highest num.
 
  // point is you must calc all backward now:
  hours = hours - days * 24;
  minutes = minutes - days * 24 * 60 - hours * 60;
  seconds = seconds - days * 24 * 60 * 60 - hours * 60 * 60 - minutes * 60;
  milli = milli - days * 24 * 60 *60 * 1000 - hours * 60 * 60 * 1000 - minutes * 60 * 1000 - seconds * 1000;
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 24, 2018, 1:50am UTC](https://discourse.processing.org/t/timer-with-specific-format/6864/3 "2018-12-24T01:50:09Z")

</div>

**nf()** -\> [Processing.org/reference/nf\_.html](http://Processing.org/reference/nf_.html)

- [Forum.Processing.org/two/discussion/16001/add-0-s-to-date-time-in-the-filename-with-saveframe#Item\_3](http://Forum.Processing.org/two/discussion/16001/add-0-s-to-date-time-in-the-filename-with-saveframe#Item_3)

SimpleDateFormat -\> [Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html)

- [Forum.Processing.org/two/discussion/10067/how-to-prevent-file-overwriting#Item\_3](http://Forum.Processing.org/two/discussion/10067/how-to-prevent-file-overwriting#Item_3)
