发布网友
共4个回答
热心网友
如果你要获取的是Internet时间,可以使用NTP服务。
NTP概念简介
Network Time Protocol(NTP)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。
java实现:
import java.io.InputStream;中国大概能用的NTP时间服务器
server 133.100.11.8 prefer
server 210.72.145.44
server 203.117.180.36 //程序中所用的
server 131.107.1.10
server time.asia.apple.com
server .236.96.53
server 130.149.17.21
server 66.92.68.246
server www.freebsd.org
server 18.145.0.30
server clock.via.net
server 137.92.140.80
server 133.100.9.2
server 128.118.46.3
server ntp.nasa.gov
server 129.7.1.66
server ntp-sop.inria.frserver 210.72.145.44(国家授时中心服务器IP地址)
ntpdate 131.107.1.10
ntpdate -s time.asia.apple.com
热心网友
java获取网络时间
try {
URL url = new URL("http://www.bjtime.cn");// 取得资源对象
URLConnection uc = url.openConnection();// 生成连接对象
uc.connect(); // 发出连接
long ld = uc.getDate(); // 取得网站日期时间
Date date = new Date(ld); // 转换为标准时间对象
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int day = calendar.get(Calendar.DAY_OF_MONTH);
if (day == 6) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
热心网友
中国科学院国家授时中心
string webUrl = http://www.ntsc.ac.cn
/**
* 获取指定网站的日期时间
*
* @param webUrl
* @return
* @author SHANHY
* @date 2015年11月27日
*/
private static String getWebsiteDatetime(String webUrl){
try {
URL url = new URL(webUrl);// 取得资源对象
URLConnection uc = url.openConnection();// 生成连接对象
uc.connect();// 发出连接
long ld = uc.getDate();// 读取网站日期时间
Date date = new Date(ld);// 转换为标准时间对象
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);// 输出北京时间
return sdf.format(date);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
热心网友
是在网页里写吗???追问不是,用java代码获取的