lovejs lovejs - 3 months ago 15
Ajax Question

Calculating download time with javascript

Hey guys am new to javascript actually..i am trying to find the download time of a file.So i have dind the size of the file and divided it with the current time ..but its not giving me the correct result.

The code i have tried

function get_filesize(url, callback) {
var xhr = new XMLHttpRequest();"HEAD", url, true); // Notice "HEAD" instead of "GET",
// to get only the header
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {

get_filesize("", function(size) {

var estimatedtime = (new Date().getTime())/size;


when i done do this i get output as

What am expecting is to get the time in
in the console.

How can i acheive this ??..Any help would be great Thanks


After you calculate the value, convert it to date like below (of course, change the hardcoded value to estimatedtime):

var time = new Date(32245538.389347337);
alert(time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds());