I set up the following code to check how many days have elapsed since a file has been uploaded:
function fileModified(url){ // returns modification date of a file
try{
var Oxml= new window.XMLHttpRequest();
Oxml.open("HEAD", url, false);
Oxml.send(null);
if(Oxml.status== 200){
var lastmod = Oxml.getResponseHeader('Last-Modified');
return lastmod;
}
else return null;
}
catch(er){
return null;
}
}
// Calculate how many days since file was modified till now
modified = fileModified(location.href);
var now = new Date();
var msecsPerDay = 1000 * 60 * 60 * 24;
var msecsDiff = now.getTime() - modified.getTime();
var diff= msecsDiff / msecsPerDay ;
alert("Days since file was uploaded= "+diff);
My problem is that modified.getTime() doesn’t work. Apparently the result of Oxml.getResponseHeader(‘Last-Modified’) is a string, such as Sun, 21 Nov 2010 21:17:49 GMT.
I tried and tried - but couldn’t get to make a proper date out of this.
The final result that I need is the time since the file was uploaded.
Thanks!