首页 行业资讯 宠物日常 宠物养护 宠物健康 宠物故事

java代码怎样获取internet标准时间?

发布网友

我来回答

5个回答

热心网友

获取internet标准时间,参考以下代码:

TimeZone.setDefault(TimeZone.getTimeZone("GMT+8")); // 时区设置  
URL url=new URL("
);//取得资源对象
URLConnection uc=url.openConnection();//生成连接对象  
uc.connect(); //发出连接  
long ld=uc.getDate(); //取得网站日期时间(时间戳)  
Date date=new Date(ld); //转换为标准时间对象  
//分别取得时间中的小时,分钟和秒,并输出  
System.out.print(date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒");

热心网友

public static void main(String[] args) throws Exception {
URL url=new URL("http://www.bjtime.cn");//取得资源对象
URLConnection uc=url.openConnection();//生成连接对象
uc.connect(); //发出连接
long ld=uc.getDate(); //取得网站日期时间
Date date=new Date(ld); //转换为标准时间对象
//分别取得时间中的小时,分钟和秒,并输出
System.out.print(date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒");
}

热心网友

用date()方法,Date date = new Date(); 就是这样,然后调用就可以了

热心网友

Date date = new Date();

热心网友

new Date()

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com