Getting the Date of URL connection in Java
Last Updated :
05 Nov, 2020
HttpURLConnection class is the class in java which deals with all the operations related to URL connection. getDate() method of HttpURLConnection class is the method that is used to get the date and time of the URL Connection.
Syntax:
Obj.getDate() // Obj is object of HttpUrlConnection class
Parameter: This method does not take any parameter. It is just used along with a HttpUrlConnection Object from which we want to fetch the date and time of the connection.
Return values: It returns the day, date and time of connection.
Below is the code implementation to get the date of the URL connection.
Java
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.concurrent.TimeUnit;
class Main {
public static void main(String args[])
throws IOException, InterruptedException
{
HttpURLConnection httpCon
= (HttpURLConnection)url.openConnection();
long date = httpCon.getDate();
if (date == 0 )
System.out.println( "No date information." );
else {
System.out.println( "Date: " + new Date(date));
}
}
}
|
Output:-
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...