calculating elapsed time on webpage

Posted on 2009-02-09
Last Modified: 2012-05-06
Hi, I would like to be able to calculate the elapsed time from my webpage (page.htm) opening to the clicking of a submit button on page.htm which submits the time variable to my php file. The time would be in the format 00:00:00, where it is hours:minutes:seconds.

Could somebody give me the code for this? I would imagine I will need to put something in the head section and some code on the submit button.

Question by:RupertA
    LVL 16

    Accepted Solution

    I would just use PHP for this.  Then when the page loads you set a varaible to a hidden form field for the time started.

    Then when the form is submitted, on whatever page you are submitting to, the first thing you do is get the current time from the submit page and you have the end time and the begin time from the page load time and you can just do a date subtract to get the difference.


    Author Comment

    Thanks for your reply brad, I actually ended up using some code on another thread shown below. However I wil hand out points as you did help and am sure yours would be a workable solution. But this is what I came up with

    as a rough idea - the big number is milliseconds

    <script type="text/javascript">
    var d = new Date();
    document.write(d.getHours() + ":" +d.getMinutes()+":" +d.getSeconds() +"<br/>");


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now