Last Modified Date of a file on a web site

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

Is there a way to get the Last-Modified-Date of a file on a Web Site?

i.e. Here is an example file I have out there: http://www.ymcadetroit.org/atf/cf/%7B2101903E-A11A-4532-A64D-9D823368A605%7D/Birmingham_Youth_Sports_Parent_Manual.pdf

回答1:

Go to the website you want to know about, wait for it to fully load, then go to the address bar and write this:

javascript:alert(document.lastModified) 

You'll get a popup that says when it was last modified.



回答2:

The HTTP intends the Last-Modified header field to declare the last modification date. But the server needs to know that date.

On static files whose content is sent directly to the client and not interpreted otherwise by the server (e.g. .html, .css, .js) it uses the last modified date of that file. But on files that generated content dynamically (PHP, Python, etc.) the script needs to specify that information itself. But unfortunatly many scripts don’t to that.

So if a Last-Modified header field is present, you can use that information. But if not, you cannot determin the last modification date.



回答3:

I realize this question is 4 years old, but a search of the web proved that satisfactory answers remain rare. Peter's answer is part of the solution. When I had the same problem to solve, that got me started. But the rest of the solution...

As he said, the web server must be configured to send the last-modified date ... so how do you configure the web server?

Assuming you have the necessary level of control, you first need to enable server side includes. There are several ways to do this - one of which is the "xbithack". A good reference is http://httpd.apache.org/docs/current/howto/ssi.html.

Assuming you've done this, you need to set the execute bit on any html file that needs to have server-side includes parsed. This can be done at the command line of a UNIX-like system: chmod u+x file.html or on the Mac using get-info (command-I) on the file.

This leaves the snippet to actually put in your file, which looks like this:

This document last modified <!--#flastmod file="index.html" -->

Since I found many, many recommendations that didn't include this, and simply used the javascript document.lastModified, I suspect that some servers give you what you want with the javascript version, whereas some (including the one hosting our stuff) don't.



回答4:

Here is some C# code to do it:

public DateTime GetLastModifyTime(string url) {         WebRequest request = WebRequest.Create(url);         request.Credentials = CredentialCache.DefaultNetworkCredentials;         request.Method = "HEAD";          using (WebResponse response = request.GetResponse())         {             string lastModifyString = response.Headers.Get("Last-Modified");             DateTime remoteTime;             if (DateTime.TryParse(lastModifyString, out remoteTime))             {                 return remoteTime;             }              return DateTime.MinValue;         } } 


回答5:

I believe the web server must be configured to send the last-modified date in an HTTP-header, this is certainly one way. Check out section 14.29 Last-Modified of this document:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html



回答6:

To obtain the last modified date from client side, you can access the HTML DOM using the lastModified property using JavaScript.

The lastModified property grabs the information from the head portion sent with all web requests. The value can be manually set by developers on the web-server side of things so it may not reflect the actual last modified date of the file responsible for delivering the content.

Example

<!DOCTYPE html> <html> <body>    <b>document.lastModified : </b> <script>document.write( document.lastModified );</script>  </body> </html>

The specific command in JavaScript that retrieves this is document.lastModified and can easily be converted into a Date object as follows :

var x = new Date(document.lastModified); 

More information can be found on the site I used as a reference w3 schools : HTML DOM lastModified Property



回答7:

With just plain HTML, no you cannot.

You can with PHP, or ASP, or any other server side language.



回答8:

I'm not an expert in headers, but believe you are looking for this:

There is a way to check the date when a file was modified: View HTTP headers in Google Chrome?

Check in there (Chrome's Developer Tools / Network / Selected File / Headers) the "If-Modified-Since" variable.

Until now this has helped me to achieve what you are asking, get a file's modification date.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!