Latest web development tutorials

Java Contoh - Dapatkan informasi URL respon tanggal sundulan

Contoh Java Contoh Java

Contoh berikut menunjukkan bagaimana menggunakan metode HttpURLConnection httpCon.getDate () untuk mendapatkan URL untuk informasi respon tanggal 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("../../www.w3cschool.cc/index.html");
      HttpURLConnection httpCon = 
      (HttpURLConnection) url.openConnection();
      long date = httpCon.getDate();
      if (date == 0)
      System.out.println("无法获取信息。");
      else
      System.out.println("Date: " + new Date(date));
   }
}

Kode di atas dijalankan output:

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

Contoh Java Contoh Java