以下實例示範如何使用HttpURLConnection 的httpCon.getDate() 方法來取得URL回應頭的日期資訊:
/* 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)); }}
以上程式碼執行輸出結果為:
Date: Mon May 04 11:57:06 CST 2015
以上就是Java 實例- 取得URL回應頭的日期的內容,更多相關內容請關注PHP中文網(www.php.cn)!