Hi everyone, I'm a beginner in javascript and I am currently working on finding the download time of a file. I have calculated the size of the file and divided it by the current time, but unfortunately, I am not getting the correct result.
This is the code I have attempted:
function get_filesize(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open("HEAD", url, true);
xhr.onreadystatechange = function() {
if (this.readyState == this.DONE) {
callback(parseInt(xhr.getResponseHeader("Content-Length")));
}
};
xhr.send();
}
get_filesize("http://upload.wikimedia.org/wikipedia/commons/9/96/Google_web_search.png", function(size) {
var estimatedtime = (new Date().getTime())/size;
console.log(estimatedtime);
});
After running this code, I received an output of 32245538.389347337
.
My goal is to display the time in hh:mm:ss
format in the console. Can anyone provide guidance on how I can achieve this? Any assistance would be greatly appreciated. Thank you.