Timer with specific format

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