[eluser]bretticus[/eluser]
An easier and more accurate way would be to store it in a database table. Use sessions to keep track of the user. Measuring time is then just a comparison of the times for adjoining database records.
If you want to keep the js route. Look into the javascript
onunload event of jquery
unload. You could, perhaps, hijack the url as you leave or call an ajax routine. Like I said, the former is easier
Good luck!
EDIT: google analytics and omniture, etc. have the page call some javascript url at their websites. Assuredly, this timestamp is stored it in a database also.