<button onclick=f()>click</button> <script> function f(){var d=new Date();setTimeout(function(){f1(d)},5000)}; function f1(d){var d1=new Date();alert(d1-d);}; </script>