Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

calculating elapsed time on webpage

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.

1 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.

RupertAAuthor Commented:
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/>");


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now