Java Example - Getting Date Information from URL Response Headers
The following example demonstrates how to use the httpCon.getDate() method of HttpURLConnection to get the date information from the URL response header:
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("");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
long date = httpCon.getDate();
if (date == 0)
System.out.println("Unable to get information.");
else
System.out.println("Date: " + new Date(date));
}
}
The output of the above code is:
Date: Mon May 04 11:57:06 CST 2015
YouTip