Display HH:MM:SS?

Hello!
Can you teach me on how can I display HH:MM:SS? What should I remove here?

#include <DateTime.h>

// macros from DateTime.h 
/* Useful Constants */
#define SECS_PER_MIN  (60UL)
#define SECS_PER_HOUR (3600UL)
#define SECS_PER_DAY  (SECS_PER_HOUR * 24L)
 
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)  
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN) 
#define numberOfHours(_time_) (( _time_% SECS_PER_DAY) / SECS_PER_HOUR)
#define elapsedDays(_time_) ( _time_ / SECS_PER_DAY)  

void setup(){
 Serial.begin (9600);
}

void loop(){  
  time(millis() / 1000);
  delay(1000);
}

void time(long val){  
 int days = elapsedDays(val);
 int hours = numberOfHours(val);
 int minutes = numberOfMinutes(val);
 int seconds = numberOfSeconds(val);

  // digital clock display of current time
  Serial.print(days,DEC);  
  printDigits(hours);  
  printDigits(minutes);
  printDigits(seconds);
  Serial.println();  
  
}

void printDigits(byte digits){
  // utility function for digital clock display: prints colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits,DEC);  
}

What should I remove here?

Serial.print(days,DEC);

millis() reports the number of milliseconds since the Arduino restarted. It has NOTHING to do with what time it is now.

You are barking up the wrong tree.

No, not real time. I will be storing the number of hours when the fan I am monitoring turns on.
I want to display HH:MM:SS instead of DD:HH:MM:SS like 24:00:00 instead of 1:00:00:00.

Sorry I bothered you. I've been replacing time(millis()/1000) with time(86400000) to check for 24 hours :roll_eyes: I forgot the /1000.

This is what I used:

#include <DateTime.h>

/* Useful Constants */
#define SECS_PER_MIN  (60UL)
#define SECS_PER_HOUR (3600UL)
 
/* Useful Macros for getting elapsed time */
#define numberOfSeconds(_time_) (_time_ % SECS_PER_MIN)  
#define numberOfMinutes(_time_) ((_time_ / SECS_PER_MIN) % SECS_PER_MIN) 
#define numberOfHours(_time_) (( _time_ / SECS_PER_HOUR) % SECS_PER_HOUR) 

void setup(){
 Serial.begin (9600);
}

void loop(){  
  time(millis()/1000);
  delay(1000);
}

void time(long val){  
 int hours = numberOfHours(val);
 int minutes = numberOfMinutes(val);
 int seconds = numberOfSeconds(val);

  // digital clock display of current time
  Serial.print(hours,DEC);    
  printDigits(minutes);
  printDigits(seconds);
  Serial.println();  
  
}

void printDigits(byte digits){
  // utility function for digital clock display: prints colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits,DEC);  
}

But now (with the last code) is working, right?

arduinoTime:
No, not real time. I will be storing the number of hours when the fan I am monitoring turns on.
I want to display HH:MM:SS instead of DD:HH:MM:SS like 24:00:00 instead of 1:00:00:00.

try something like this:

unsigned long oneSecond = 1000UL;
unsigned long startTime;
int mySeconds = 0;
int myMinutes = 0;
int myHours = 0;
int myDays = 0;

void setup()
{
  Serial.begin(9600);
  startTime = millis();
}

void loop()
{
  if (millis() - startTime >= oneSecond)
  {
    displayTime();
    mySeconds++;
    startTime += oneSecond;
    if (mySeconds > 59)
    {
      myMinutes++;
      mySeconds = 0;
      if (myMinutes > 59)
      {
        myHours++;
        myMinutes=0;
        if (myHours > 23)
        {
          myDays++;
          myHours=0;
        }
      }
    }
  }
  //your other code here.....
}

void displayTime()
{
  //Serial.print(myDays);
  //Serial.print(":");
  if (myHours < 10) Serial.print("0");
  Serial.print(myHours);
  Serial.print(":");
  if (myMinutes < 10) Serial.print("0");
  Serial.print(myMinutes);
  Serial.print(":");
  if (mySeconds < 10) Serial.print("0");
  Serial.println(mySeconds);
}

or do all the work in the updateDisplay() function if you like:

void loop()
{
  if (millis() - startTime >= oneSecond)
  {
    displayTime();
  }
  //your other code here.....
}

void displayTime()
{
  startTime += oneSecond;
  if (mySeconds > 59)
  {
    myMinutes++;
    mySeconds = 0;
    if (myMinutes > 59)
    {
      myHours++;
      myMinutes=0;
      if (myHours > 23)
      {
        myDays++;
        myHours=0;
      }
    }
  }
  //Serial.print(myDays);
  //Serial.print(":");
  if (myHours < 10) Serial.print("0");
  Serial.print(myHours);
  Serial.print(":");
  if (myMinutes < 10) Serial.print("0");
  Serial.print(myMinutes);
  Serial.print(":");
  if (mySeconds < 10) Serial.print("0");
  Serial.println(mySeconds);
  mySeconds++;
}