views:

26

answers:

1

How do you get the modified date of a web resource in Java?

URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.connect();
// What now?
+3  A: 
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
connection.connect();
long time = connection.getLastModified();

Javadoc

Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT.

skaffman
Indeed. To be clear: this information comes from HTTP [`Last-Modified`](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.29) header. It's the server's responsibilty to set it. If it's absent, you can't reveal it and it will return 0.
BalusC
Thanks skaffman and BalusC for the clarification.
hgpc