Home > Java > javaTutorial > Java Example - Obtain date information from URL response header

Java Example - Obtain date information from URL response header

黄舟
Release: 2017-01-21 10:47:15
Original
1373 people have browsed it

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

/*
 author by w3cschool.cc
 Main.java
 */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.w3cschool.cc");
      HttpURLConnection httpCon = 
      (HttpURLConnection) url.openConnection();
      long date = httpCon.getDate();
      if (date == 0)
      System.out.println("无法获取信息。");
      else
      System.out.println("Date: " + new Date(date));
   }}
Copy after login

The output result of the above code is:

Date: Mon May 04 11:57:06 CST 2015
Copy after login

The above is the Java example - getting the date information of the URL response header. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template