Using time function in arduino
As Majenko said you can use the millis() keyword.

Unless millis is not accurate enough. In that case you can use micros(), but this overflows every 70s if I'm correct, but you can offset it against millis().

If you need to compare two values, what you can do is:


get millis()
get micros()
read sensor data (optimize if needed)
get micros()


Average the difference of the micros, and add it to millis, and you have the average time for the sensor data readings.

Of course if it doesn't matter that all sensor data is read at approximately the same time, you can use millis() for each sensor data reading and work with those values.