Getting the Date of URL connection in Java Last Updated : 05 Nov, 2020 Comments Improve Suggest changes Like Article Like Report 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 // Java Program to get the date of the URL connection 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 { // getting the URL class object URL url = new URL("http://www.yahoo.com"); // opening the connection HttpURLConnection httpCon = (HttpURLConnection)url.openConnection(); // getting the date of URL connection long date = httpCon.getDate(); /* Other working of program */ // if date is 0,it means there is no // information regarding date if (date == 0) System.out.println("No date information."); else { // print the date using object of Date class System.out.println("Date: " + new Date(date)); } } } Output:-Â Comment More infoAdvertise with us Next Article Getting the Date of URL connection in Java L lavishgarg26 Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads Java Program to Get Components of a URL Java Networking: As java programs are written to be executed across multiple devices whereby multiple devices are meant computers present in remote locations. So both devices can communicate be present in the same locations or different locations connected with some network. For java networking 'net 3 min read Java Program to Get the Creation Time of a File Use java.nio package for extracting the creation date and time of any file through java. To extract the date and time of the file use BasicFileAttributes class. java.nio package helps us to get the creation time, last access time, and last modified time, it works for both file and directory. Approac 2 min read How to Convert java.sql.Date to java.util.Date in Java? If we have the Date object of the SQL package, then we can easily convert it into an util Date object. We need to pass the getTime() method while creating the util Date object. java.util.Date utilDate = new java.util.Date(sqlDate.getTime()); It will give us util Date object. getTime() method Syntax: 1 min read How to Convert java.util.Date to java.sql.Date in Java? Date class is present in both java.util package and java.sql package. Though the name of the class is the same for both packages, their utilities are different. Date class of java.util package is required when data is required in a java application to do any computation or for other various things, 3 min read How to Convert a String to URL in Java? In Java, a string is a sequence of characters. A URL, which is short for Uniform Resource Locator, refers to a web resource that specifies its location on a computer network and provides the mechanism for retrieving it. To represent a URL in Java, we use the java.net.URL class. In this article, we w 2 min read Like