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"/>
15 回答8.4k 阅读
8 回答6.2k 阅读
1 回答4k 阅读✓ 已解决
3 回答6k 阅读
3 回答2.2k 阅读✓ 已解决
2 回答3.1k 阅读
2 回答3.8k 阅读
URLConnection getDate方法返回的是原始服务器消息发出的时间,并非标准的网络时间。getDate方法本身不存在抛出异常。你遇到了什么异常?