Java 实例 - 获取 URL响应头的日期信息

Java 教程 · 2019-02-11 21:57:45

以下实例演示了如何使用 HttpURLConnection 的 httpCon.getDate() 方法来获取 URL响应头的日期信息:

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.codercto.com"); 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 教程 文章: https://codercto.com/courses/l/12.html

查看所有标签

The Art of Computer Programming, Volume 4,  Fascicle 3

The Art of Computer Programming, Volume 4, Fascicle 3

Donald E. Knuth / Addison-Wesley Professional / 2005-08-05 / USD 19.99

Finally, after a wait of more than thirty-five years, the first part of Volume 4 is at last ready for publication. Check out the boxed set that brings together Volumes 1 - 4A in one elegant case, and ......一起来看看 《The Art of Computer Programming, Volume 4, Fascicle 3》 这本书的介绍吧!

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具