Your question is not at all clear, but it sounds like you should be able to wrap System.currentTimeMillis() in an object that maintains a starting point and returns the offset. Something like

public class Millis
{
    long start;
    public Millis() { this.reset(); }
    public void reset() { this.start = System.currentTimeMillis(); }
    public long getMillis() { return System.currentTimeMillis() - start; }
}

You create an instance of this class at startup

Millis timer = new Millis();

then call reset() to set it back to zero at the beginning of each game. Everywhere in your code you currently have millis() you would have timer.getMillis()

Answer from Jim Garrison on Stack Overflow
๐ŸŒ
Processing Forum
forum.processing.org โ€บ two โ€บ discussion โ€บ 19478 โ€บ can-you-reset-a-timer-using-millis
Can you reset a timer using millis()? - Processing 2.x and 3.x Forum
December 2, 2016 - saved millis variable text(start/1000, 10,height/3); // how long has the timer been running? current millis - saved millis runtime = millis() - start; text(runtime/1000, 10,height/2); } void keyPressed(){ // mark a new timer start time start ...
๐ŸŒ
Processing Forum
forum.processing.org โ€บ one โ€บ topic โ€บ how-to-reset-count-time.html
how to reset count time - Processing Forum
December 20, 2012 - and so you just get the first time millis is over 5000. what you wanna do is more like this: ... Thank you csteinlehner!! I put the println(m) inside the if to see whats going on.. it outputs number around 5000 so I guess it worked.. but I dont understand the meaning of it..
Discussions

Reset millis() - Processing Forum
Is there a way to reset millis() e.g. to restart a timer? ... No, usually, you reset the reference point from a given time. ... How can I initialise an object from... More on forum.processing.org
๐ŸŒ forum.processing.org
October 20, 2011
programming - Resetting millis() and micros() - Arduino Stack Exchange
I want to know how much time has elapsed since a certain event, and I do not want to use any external timers. It seems logical to reset an internal timer whenever the event occurs (using an interru... More on arduino.stackexchange.com
๐ŸŒ arduino.stackexchange.com
How do I make the timer stop and reset? - Processing 2.x and 3.x Forum
It's really supposed to be the number of seconds SINCE THE TIMER RESET. So, how do we know when the timer reset? Well, how do we know a time at all in a sketch? Ah ha! We have the function millis() that tells us how many milliseconds have passed since the sketch started! More on forum.processing.org
๐ŸŒ forum.processing.org
March 23, 2018
Time reset - Processing Forum
I have tried some of the things that I had read with no luck. So basically I am using a switch to run my menu>game>end screen. At the end screen it has a replay button. So I want the game to reset the time to start at 0:0:0, but it starts where I had left off. ... I tried putting a method in the ... More on forum.processing.org
๐ŸŒ forum.processing.org
September 20, 2013
๐ŸŒ
Bald Engineer
baldengineer.com โ€บ home โ€บ arduino: how do you reset millis() ?
Arduino: How do you reset millis() ? - Bald Engineer
March 31, 2022 - The quick answer to โ€œHow do you reset millis()โ€ is: You Donโ€™t! And hereโ€™s why: if you did, it would potentially break most libraries and functions that rely on it. Generally the reason people want to reset it, is that they are concerned about rollover. Instead of focusing on resetting millis(), here is how to use it correctly.
Top answer
1 of 3
6

millis() and micros() overflow periodically. However, this is not a problem: as long as you compare durations instead of timestamps you can forget about the overflows.

The liked answer also gives the trick for resetting millis(). Can be handy for testing purposes, but you do not need this to handle the millis() rollover problem. Notice that there is no clean way to reset micros(): it relies on a static variable, i.e. a variable private to the file defining it.

2 of 3
5

Overflow is never really an issue if you always calculate time difference. (Unless the time difference is more that 50 days.)

unsigned long previousTime = millis();
... wait for some event to happen ...
unsigned long elapsedTime =  millis() - previousTime;

Even if previousTime was before the overflow, and millis() is after the overflow (so essentially millis()<previousTime), elapsedTime will still be the correct value.

This is because the calculation itself will also overflow. Since millis()<previousTime, the result would be negative, but the type of the variable is unsigned, so it wraps around. I hope that makes sense.

Just don't ever do something like if( millis() > (previousTime+1000) )

If you still want to reset millis, you can use the following:

extern volatile unsigned long timer0_millis;
unsigned long new_value = 0;

void setup(){
  //Setup stuff
}

void loop(){
  //Do stuff
  //--------

  //Change Millis
  setMillis(new_value);
}

void setMillis(unsigned long new_millis){
  uint8_t oldSREG = SREG;
  cli();
  timer0_millis = new_millis;
  SREG = oldSREG;
}
๐ŸŒ
Processing Forum
forum.processing.org โ€บ two โ€บ discussion โ€บ 27070 โ€บ how-do-i-make-the-timer-stop-and-reset
How do I make the timer stop and reset? - Processing 2.x and 3.x Forum
March 23, 2018 - The trick is that we take the moment "v" is pressed (let's say at 11000 millis) and measure the time since then. The core idea is to measure the time since then. ... so you got to call reset() whenever v is pressed (or when you want a reset ...
๐ŸŒ
Processing Forum
forum.processing.org โ€บ two โ€บ discussion โ€บ 22459 โ€บ how-to-use-timer-millis-properly
How to use timer (millis()) properly - Processing 2.x and 3.x Forum
May 8, 2017 - int time; void setup() { size(400, 400); } void draw() { background(0); fill(64); if (dist(mouseX, mouseY, 200, 200)<100) { fill(128); if (millis() > time) { fill(255); } } else { time = millis() + 3000; } ellipse(200, 200, 200, 200); } ... Yup, ...
Find elsewhere
๐ŸŒ
Processing Forum
forum.processing.org โ€บ two โ€บ discussion โ€บ 19308 โ€บ how-to-reset-my-sketch-every-9-000-millisecond
How to reset my sketch every 9,000 millisecond - Processing 2.x and 3.x Forum
November 26, 2016 - You wouldn't reset the millis() function. You would keep track of the last time the sketch was reset, and then check against that value.
๐ŸŒ
Du
cs.du.edu โ€บ ~leut โ€บ 1671 โ€บ 09_Fall โ€บ ProcessingNotes7.pdf pdf
Processing Notes 7 Chapter 15: Timer/Stopwatch Class
return ( (int) (timeSoFar / 1000.0) ) ; } void start() { running = true ; startTime = millis() ; } Copyright 2009, Leutenegger ยท 2 ยท void restart() // reset the timer to zero and restart, identical to start ยท { start() ; } void pause() { if (running) { timeSoFar = millis() - startTime ; ...
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
resetting millis() - Programming - Arduino Forum
October 11, 2016 - Hi I want to reset the millis() function to zero each 24 hours. I cant find a post in the forum that describes this, is there anyone that can help me? best regards Fredrik
๐ŸŒ
Processing Forum
forum.processing.org โ€บ two โ€บ discussion โ€บ 25970 โ€บ restart.html
Restart - Processing 2.x and 3.x Forum
January 15, 2018 - Conversely, if you need to know the total frames (not counting setup) since the sketch started -- (although you almost certainly don't) -- you can add a global variable for that and track it at the beginning of draw. int millisLastSetup; // last setup time int frameCountTotal; void setup{ // all global variable values must be assigned in setup // and the canvas must be cleared millisLastSetup = millis(); } void draw(){ frameCountTotal++; } void reset(){ frameCount = -1; } void millis2(){ return millis() - millisLastSetup; } That gives you a basic sketch reset based on setup(), with features for accessing either millis and either frameCount.
๐ŸŒ
Reddit
reddit.com โ€บ r/processing โ€บ millis() not resetting properly in rolling() method
r/processing on Reddit: millis() Not Resetting Properly in rolling() Method
December 2, 2023 -

I'm working on a game in Processing and facing an issue where millis() is not resetting as expected in my rolling() method within the Player class. The method is triggered by pressing the down arrow, and it's supposed to reset the rolling timer. However, the values of roll and rollingTimer are not updating correctly. The stamina += 3 line in the same method works fine, indicating that the method is executing. I've added println statements for debugging, which suggest the issue is around the millis() reset. Below are the relevant classes of my code

class King extends Character{ float sideBlock; float attackBuffer; boolean miss; float attackTimerEnd; float elementBlock; float deathTimer; float animationTimer; float blockTimer; float missTimer;

  King(PVector pos, int health, float attackTimer, int damage){
    super(pos, health, attackTimer, damage);
    sideBlock = 0;
    MAX_HEALTH = 10;
    attackTimer = millis();
    attackBuffer = -1;
    miss = false;
    attackTimerEnd = 10000;
    deathTimer = -1;;
    activeKingImg = kingDefault;
    blockTimer = -1;
    missTimer = -1;
  }
  
  void drawMe(){
    pushMatrix();
    translate(pos.x, pos.y);
    scale(3,3);
    if (activeKingImg != null) {
        image(activeKingImg, 0, 0);
    }
    popMatrix();
  }
  
  void death(){
    attackTimer = millis();
    knight.health = 10;
    gameState = LEVEL_TWO;
  }
  
  void drawDeath(){
    activeKingImg = kingDeathAnimation;
  }
  
  void attackingAnimation(){
    activeKingImg = kingAttack;
    animationTimer = millis();
  }
  
  void displayMiss(){
    if (millis() - missTimer < 500){
    translate(pos.x + 50, pos.y-100);
    strokeWeight(1);
    fill(0);
    textSize(20);
    text("Miss!", width/4, width/3);
    }
  }
  
  void displayBlocked(){
    if (millis() - blockTimer < 500){
    pushMatrix();
    translate(pos.x + 50, pos.y-100);
    strokeWeight(1);
    fill(0);
    textSize(50);
    text("Blocked!", width/4, width/3);
    popMatrix();
    }
  }
  
  void nullifyLeft(){
   if (sideBlock < 1 && health >= 0 && millis() - animationTimer > 1100){
   pushMatrix();
   translate(pos.x,pos.y);
   activeKingImg = kingLeftBlock;
   popMatrix();
   }
 }
 
  void nullifyRight(){
   if (sideBlock >= 1 && health >= 0 && millis() - animationTimer > 1100){
   pushMatrix();
   translate(pos.x,pos.y);
   activeKingImg = kingRightBlock;
   popMatrix();
   }
 }
  
  void autoAttack(){
    if(health >= 0){
    if (millis() - attackTimer >= attackTimerEnd) {
    attackTimer = millis();
    attackBuffer = millis();

  }

  if (attackBuffer >= 0 && millis() - attackBuffer <= 1000) {
    if (millis() - knight.roll <= 500) {
      println("missing");
      miss = true;
      missTimer = millis();
    }
    attackingAnimation();
  }

  if (attackBuffer >= 0 && millis() - attackBuffer >= 1000) {
    println(miss);
    if (miss == false) {
      hit(knight,1);
      activeKingImg = kingAttackFinish;
      animationTimer = millis();
      println(knight.health);
      knight.clearCombos();
    }
    miss = false;
    println(knight.health);
    attackBuffer = -1;
  }
    }
  }
  void drawDamage(){
    activeKingImg = kingTakeDamage;
    animationTimer = millis();
  }
  
  void update(){
   super.update();
   if (health <= 0){
     drawDeath();
     if (deathTimer <= -1){
       deathTimer = millis();
     }
   if (deathTimer >= 1000){
     death();
   }
   }
  if (millis() - animationTimer < 1000) {
    return;
  }
   nullifyLeft();
   nullifyRight();
   nullify();
   autoAttack();
   
   displayBlocked();
   displayMiss();
  }
 
  void drawHealthBar(){
    super.drawHealthBar();
  }
  
  void nullify(){
    if (knight.combos.size() >= 1){
      if (sideBlock < 1 && knight.combos.get(0) == 1){
        nullify = true;
    }else if (sideBlock >= 1 && knight.combos.get(0) == 2){
        nullify = true;
    }
    }
  }
}

class Player extends Character{
  boolean prep, dodge;
  float roll;
  int stamina;
  float preppingTimer;
  float rollingTimer;
  float animationResetTimer;
  float staminaTimer;

  
  ArrayList<Integer> combos = new ArrayList<Integer>();
  
  Player(PVector pos, int health, float attackTimer, int damage){
    super(pos, health, attackTimer, damage);
    prep = false;
    dodge = false;
    roll = millis();
    attackTimer = millis();
    stamina = 6;
    preppingTimer = -1;
    rollingTimer = -1;
    MAX_HEALTH = 10;
    activeFrames = defaultSword;
    animationResetTimer = millis();
    staminaTimer = -1;

  }

  void updateFrame() {
   super.updateFrame();
   
  }

  void clearCombos(){
    combos.clear();
  }
  
  void notEnoughStamina(){
    if (millis() - staminaTimer < 500);
    pushMatrix();
    translate(pos.x, pos.y);
    strokeWeight(1);
    fill(0);
    textSize(50);
    text("Not enough \nstamina!", width/2 + width/4 + 50, width/3 + width/3);
    popMatrix();
  }
  
  void restingSword(){
    activeFrames = defaultSword;
  }
  
  void attackingAnimation(){
    activeFrames = swingSword;
    animationResetTimer = millis();
  }
  
  void swordDodge(){
    activeFrames = swordDodge;
    animationResetTimer = millis();
  }
  
  void drawDamage(){
    activeFrames = swordDamage;
    animationResetTimer = millis();
  }
  
  void animationReset(){
    if (activeFrames != defaultSword && millis() - animationResetTimer > 500){
      restingSword();
    }
  }
  
  void rolling(){
    stamina += 3;
    if (stamina > 6){
      stamina = 6;
    }
    roll = millis();
    clearCombos();
    rollingTimer = millis();
    println(roll);
    println(rollingTimer);
    println("rolling");
  }
  
  void keyPressed(){
    if (millis() - roll >= 250){
    if (key==CODED && millis() - attackTimer >= 250) {
      if (keyCode==UP) prep=true;
      if (keyCode==DOWN) {println("rolling happening");rolling();swordDodge();}
    if (prep == true) {
      if (keyCode==LEFT) combos.add(1);
      if (keyCode==RIGHT) combos.add(2);
    }
    } else if (key==CODED && millis() - attackTimer <= 500) {
    preppingTimer = millis();
  }
  attackTimer = millis();
  dodge = false;
  println("Combos: " + combos);
  }else if (millis() - roll <= 500){
    dodge = true;
    rollingTimer = millis();
  }
}

  void keyReleased(){
  if (key==CODED) {
    if (keyCode==LEFT) prep=false;
    if (keyCode==RIGHT) prep=false;
    }
}
  void drawMe(){
    pushMatrix();
    translate(pos.x, pos.y);
    scale(3,6);
    if (img != null) {
        image(img, 0, 0);
    }
    popMatrix();
  }
  
  void drawDeath(){
    super.drawDeath();
  }
  
  void update(){
   super.update(); 
   displayRolling();
   displayPrepping();
   updateFrame();
   animationReset();
  }
  
  void displayRolling(){
    if (rollingTimer >= 0 && millis() - rollingTimer <= 1000){
      strokeWeight(1);
      fill(0);
      textSize(20);
      text("rolling!", width/2 + width/4 + 50, width/3 + width/3);
    }
  }
  void displayPrepping(){
    if (preppingTimer >= 0 && millis() - preppingTimer <= 1000){
      strokeWeight(1);
      fill(0);
      textSize(20);
      text("performing an \naction!", width/2 + width/4 + 50, width/3 + width/3);
    }
  }
  void drawHealthBar(){
    super.drawHealthBar();
  }
}

I know the rolling class is executing properly because the stamina += 3 is working as intended and I dont have the roll being set anywhere else aside from the constructor of the class and in the rolling method.

I've tried debugging by placing println at various points where the problem might have stemmed from and it all points back to here so I am a bit clueless as to how to solve the problem.

๐ŸŒ
Processing Foundation
discourse.processing.org โ€บ coding questions
Some questions about millis() - Coding Questions - Processing Community Forum
April 8, 2020 - I know millis() is the number of milliseconds since starting the program, but how can I reset millis() to 0 in order to re-counting the time?
๐ŸŒ
Teensy Forum
forum.pjrc.com โ€บ home โ€บ forums โ€บ main category โ€บ general discussion
Resetting millis() - again | Teensy Forum
November 30, 2022 - Trying to reset the global system milliseconds value can only cause trouble. ... Best is to use relative offsets on millis() for each timer involved.
๐ŸŒ
Learningprocessing
learningprocessing.com โ€บ examples โ€บ chp10 โ€บ example-10-04-timer
timer | Learning Processing 2nd Edition
DANIEL SHIFFMAN LEARNING PROCESSING THE NATURE OF CODE ยท timer ยท SKETCH RUNNING VIA P5.JS JS CODE / PDE CODE ON GITHUB
๐ŸŒ
Reddit
reddit.com โ€บ r/processing โ€บ trying to get timer for millis() to reset to zero indefinitely after 10 but it keeps crashing
r/processing on Reddit: Trying to get timer for millis() to reset to zero indefinitely after 10 but it keeps crashing
April 8, 2024 -

Hello, I'm relatively new to Processing and programming languages in general. There's this one sketch that I've been trying to get to work where, every 10 seconds, the timer variable (millis()/1000) resets to 0 and the program switches one image to another. Image 1 to Image 2, Image 2 to Image 1, Image 1 to Image 2 and so on.

However, due to the finicky nature of millis() (for me, at least), I can only get the program to switch images once. It crashes whenever the timer (variable named 'seconds') is supposed to set to zero for the second time. Can someone more experienced examine the code and help me out?

Screenshots of the program running
๐ŸŒ
Reddit
reddit.com โ€บ r/processing โ€บ i want to transition scenes with millis
r/processing on Reddit: I want to transition scenes with Millis
June 5, 2017 -

void group1()

{

while (millis() < 5000)

{

  developer();

}

while (millis() >= 5000)

{

  titlescreen();

  startbutton();

}

}

Thats the code, I get an error "Target VM Failed to initiate". Logically this makes sense to me. I am having a title screen that transitions. The developer logo will show, and after a few seconds, will switch to the title screen. Any ideas? I get the same error when I used if and for.