Get last modified date for a URL connection in Java

Description

The following code shows how to get last modified date for a URL connection.

Example


import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
/* www  .java2 s. c  o m*/
public class Main {

  public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.google.com");
    URLConnection uc = u.openConnection();
    System.out.println("Last modified: " + new Date(uc.getLastModified()));
  }

}

The code above generates the following result.





















Home »
  Java Tutorial »
    Network »




NetworkInterface
URI
URL
HTTP
HTTP Read
IP
Socket
UDP
URL Encode