Reputation: 4892
I want to write something in .NET that will be given a URI and return the date/time when it was last updated. Is there something easy I can check? I assume there is a last updated property I can hook into? Is this reliable? How does it work with timezones?
Thanks
Upvotes: 2
Views: 58
Reputation: 25210
There is an HTTP-Last-Modified header, which should suit your purposes. A properly configured server should return this in UTC.
Something like this might do:
using (WebClient client = new WebClient())
{
client.OpenRead("http://www.stackoverflow.com");
string lastModified = client.ResponseHeaders["Last-Modified"];
DateTime dateLastModified = DateTime.Parse(lastModified);
Console.WriteLine(string.Format("Last updated on {0:dd-MMM-yyyy HH:mm}", dateLastModified));
}
which (right now) returns
Last updated on 03-Oct-2011 12:03
Upvotes: 1