通过java获取网络时间

来源:互联网 发布:jxl导入excel到数据库 编辑:程序博客网 时间:2024/05/17 02:42


@Test
public void test001() throws IOException{

 URL url = new URL("http://www.bjtime.cn");
 //生成连接对象
 URLConnection uc = url.openConnection();
 //发出连接
 uc.connect();
 long time = uc.getDate();
 System.out.println("long time:"+time);
 Date date = new Date(time);
 System.out.println("date:"+date.toString());
 System.out.println(new SimpleDateFormat("yyyy-MM-dd hh-mm-ss").format(date));

}

0 0
原创粉丝点击