Ejemplos Java - Obtener información de URL de respuesta de cabecera de fecha
El siguiente ejemplo muestra cómo utilizar el método HttpURLConnection httpCon.getDate () para obtener la dirección URL de información de respuesta de fecha encabezados:
/* 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)); } }
El código anterior se ejecuta salida es:
Date: Mon May 04 11:57:06 CST 2015