Date.valueOf()
Under the covers, the Date object keeps track of time as the number of milliseconds since January 1st, 1970. (This value is also known as a timestamp.) Date.valueOf() returns this value, which is useful for doing math between two Dates.
Here's an example program that keeps track of how long it takes for you to press the button.