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();处报异常,此方法是不是不能直接用?
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();处报异常,此方法是不是不能直接用?
添加权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
8 回答6.8k 阅读
4 回答1k 阅读✓ 已解决
1 回答2.5k 阅读✓ 已解决
4 回答491 阅读✓ 已解决
1 回答1.1k 阅读✓ 已解决
3 回答795 阅读✓ 已解决
2 回答2k 阅读
URLConnection getDate方法返回的是原始服务器消息发出的时间,并非标准的网络时间。getDate方法本身不存在抛出异常。你遇到了什么异常?