Need help to get around useless "delay" function

i have a relay that i am turning on for 15 seconds with a switch.and more like below.how can i instead of the delay?thanks a lot.

delay(15000);
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW);

delay(3000);
digitalWrite(relayPin, HIGH);
delay(1000);
digitalWrite(relayPin, LOW);

void loop() {
  ts = millis( ); 
  if ( ts - ts2 >= 5 ) {
     display.setDigits( sbuf, 4 );
     display.update();
     ts2 += 5; // display-update interval = 5msec

}


  buttonState = digitalRead(buttonPin);
  if (buttonState != lastButtonState) {    // (pressed)
  // buttonState 會 HIGH

  if (buttonState == HIGH) {    
        // if the current state is HIGH then the button
      // went from off to on:
      buttonPushCounter++;
      Serial.print("number of button pushesON:  ");
      Serial.println(buttonPushCounter,DEC);
      sprintf( sbuf, "%04u", buttonPushCounter );
      delay(15000);
      digitalWrite(relayPin, HIGH);
      delay(1000); 
      digitalWrite(relayPin, LOW); 
       }
      
  else if (buttonState == LOW) {    
       // if the current state is LOW then the button
      // went from on to off:
      buttonPushCounter++;
      Serial.print("number of button pushesOFF:  ");
      Serial.println(buttonPushCounter,DEC);
      sprintf( sbuf, "%04u", buttonPushCounter);
      delay(3000); 
      digitalWrite(relayPin, HIGH);
      delay(1000); 
      digitalWrite(relayPin, LOW);  
      }     
   }  
lastButtonState = buttonState;  // save the current state as the last state, for next time through the loop
}

How come this Thread has exactly the same title as this other Thread? It seems an unlikely coincidence as the titles are not short.

Are you the same person as @killedoff ?

Have a look at how to use millis() to manage timing in several things at a time.

...R