Timer activated by digital output

hello world
I am making an incubator, and I would like to know how often the PID program activates the heater, kinda like its duty-cycle, in a limited period e.g. 1 hour.
I think it would have to be in an if-statement like this:

if ( digitalRead(14) == LOW && TempTime < ( time + 3600000)){

The conditions are simple enough, but how do I activate a timer inside an if-statement only? and then save that time value for the next time the if-statement is activated.

First read the StateChangeDetection example, you definitely don’t want to trigger because the heater’s on,
you want to trigger when it turns on (changes state).

You can nest if’s if you want things more readable:

  heaterState = ????? ;  // fill in the blanks

  if (heaterState == ON && oldHeaterState != ON)  // detect state changed to on
  {
    if (millies () - startTime < 3600000L)  // only count up to one hour from starttime
      counter ++ ;
  }
  oldHeaterState = heaterState ; // prepare for next time
[code]
Of course there is more to it, as you have to manage the startTime variable and report on the counter, maybe resetting them

Hi & thanks for the replay
I might have explained myself poorly.
I need to know for how long the heater is activated, in time units/seconds. As far as I can tell, that's the only unit I can use to get that information.
Like if the heater is ON 59 min of one hour (meaning underrated heater source)

That is just (run time / total time). Pick your start and end time. To time the heater:

if (millis() - lastSec >= 1000)
{
lastSec += 1000;
++totalTimer;
if (heaterIsOn)
  {
  ++heaterTimer;
  }
}