This code might not compile but gives you an idea:
unsigned long startMillis = 0;
unsigned long stopMillis = 0;
unsigned long duration = 0;
byte infraredPin = 1;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(digitalRead(infraredPin) == 0)
{
startMillis = millis();
while(digitalRead(infraredPin) == 0)
{
//Do nothing and wait
}
stopMillis = millis();
duration = stopMillis - startMillis;
Serial.println(duration);
}
}