java - 安卓中如何获取网络时间?
PHP中文网
PHP中文网 2017-04-17 17:31:14
0
1
263
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中文网

认证高级PHP讲师

reply all(1)
小葫芦

URLConnection getDate method returns the time when the original server message was sent, not the standard network time. The getDate method itself does not throw an exception. What exception did you encounter?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template