Easy Tutorial
❮ Java Iterator Java String Equals ❯

Java Example - Retrieving Date Information from URL Response Headers

Java Examples

The following example demonstrates how to use the httpCon.getDate() method of HttpURLConnection to retrieve the date information from URL response headers:

Main.java File

import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

public class Main {
   public static void main(String args[]) 
   throws Exception {
      URL url = new URL("http://www.tutorialpro.org");
      HttpURLConnection httpCon = 
      (HttpURLConnection) url.openConnection();
      long date = httpCon.getDate();
      if (date == 0)
      System.out.println("Unable to get the information.");
      else
      System.out.println("Date: " + new Date(date));
   }
}

The above code outputs the following result when run:

Date: Mon May 04 11:57:06 CST 2015

Java Examples

❮ Java Iterator Java String Equals ❯