Timer with specific format

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.

are you aware of:

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

like in

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 :

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;
}

1 Like

nf() -> Processing.org/reference/nf_.html

SimpleDateFormat -> Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html

1 Like