首页  >  问答  >  正文

java - 安卓中如何获取网络时间?

URL urlTime=new URL("http://www.bjtime.cn");//取得资源对象
URLConnection uc=urlTime.openConnection();//生成连接对象
uc.connect(); //发出连接
long ld=uc.getDate(); //取得网站日期时间
Date date=new Date(ld); //转换为标准时间对象

在uc.getDate();处报异常,此方法是不是不能直接用?
PHP中文网PHP中文网2741 天前249

全部回复(1)我来回复

  • 高洛峰

    高洛峰2017-04-17 17:33:14

    URLConnection getDate方法返回的是原始服务器消息发出的时间,并非标准的网络时间。getDate方法本身不存在抛出异常。你遇到了什么异常?

    回复
    0
  • 取消回复