Timed Relay Circuit

I'm really new to arduino's , i just got my uno and a starter kit a couple weeks ago and have been playing around with simple codes

I was just wondering if anyone could give me a simple outline of how i would go about making a code that uses a momentary switch to turn on the output of a pin for X amount of time, but when the button is pressed again it resets the delay

The purpose is to have a relay activated by a push button to control a pneumatic valve

Have you gone through the sample sketches that come with th IDE?