Arduino - Calculating the time for which a Pushbutton is pressed

Heyy guys, I'm working on a project that involves calculating the time for which a button is pressed and held as such and the time interval between two consecutive button presses where the button is not pressed. Is there any code snippets that I can use for the above two functionalities?

Look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

Basically save the millis() value when the button [u]becomes[/u] pressed and again when it [u]becomes[/u] released. The difference between the two is the number of milliseconds during which the button was pressed.

Use the same principle for your other question.

Why not read the answer you got on StackExchange, or do you just enjoy having people all over everywhere writing code for you?

@DKWATSON I'm not sure if u saw the post on stack exchange later, The code actually didn't work and I had further doubts on it which I asked over there. Unfortunately, those doubts are left uncleared over there and that is the reason I thought of posting it here.