How to used the AVR timer to time accurately

now I have a problem about timeing accurately .
if i want to do some thing within a period , how to used the timer0 or 1 for counter ? I don’t konw the AVR timer very much , have anyone can show me some information or code example… thx…

when I used 8051 befor I can use the timer interrupt like this:
TimeOutCnt = 20;
TimeOut = 0;
while (!TimeOut)
{ my acctions ;}

but now used the Arduino how to time for it ?

look into the function “millis()”, see if that can be used.

unsigned long millis()
Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days

Also lookup attachinterrupt

attachInterrupt(interrupt, function, mode)

Specifies a function to call when external interrupt 0 or 1 occurs, on digital pin 2 or 3, respectively. Replaces any previous function that was attached to the interrupt.

thx for your help … and the millis() seems useful ~ ;D