// Simple 24-hour format time dislay on serial moitor by kidkara

unsigned long curmil;
unsigned long prevmil;
const unsigned long duration=1000;

int sec=0;
int min=0;
int hour=0;

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

void loop() 
{
  curmil=millis();
  if(curmil-prevmil>=duration)
  {
    sec=++sec;
    if(sec==60)
    {
       min=++min;
       sec=0;
    }

    if(min==60)
    {
       hour=++hour;
       min=0;
    }
    
    if(hour>=24)
    {
      hour=0;
    }
    Serial.println("HH:MM:SS");
     
    if(hour<10)
    {
       Serial.print("0");
       Serial.print(hour);
       Serial.print(":");
    }
    else
    {
       Serial.print(hour);
       Serial.print(":");
    }

    if(min<10)
    {
       Serial.print("0");
       Serial.print(min);
       Serial.print(":");
    }
    else
    {
       Serial.print(min);
       Serial.print(":");
    }

    if(sec<10)
    {
       Serial.print("0");
       Serial.println(sec);
    }
    else
    {
       Serial.println(sec);
    }
  Serial.println("");  
    prevmil=curmil;
  }

}