日期:2014-05-17 浏览次数:21071 次
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.net.HttpURLConnection"%>
<%@ page import="java.net.URL"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%
HttpURLConnection con =
(HttpURLConnection)new URL("http://www.baidu.com").openConnection();
con.setUseCaches(false);
con.setInstanceFollowRedirects(false);
String dateStr = con.getHeaderField("Date");
if(dateStr!=null){
Date now = new Date(dateStr); //这里已获得当前北京时间
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
out.print(fmt.format(now));
}
%>
------解决方案--------------------
做个线程一秒钟获取一下时间就ok