首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

有没有同步时间接口,该怎么解决

2013-01-01 
有没有同步时间接口如题一个封装好的api我们直接访问能获取当时时间的,不需要任何参数。。。求share。。tks[解

有没有同步时间接口
如题
一个封装好的api
我们直接访问能获取当时时间的,不需要任何参数。。。

求share。。

tks
[解决办法]

public static void main(String[] args) throws Exception {
       URL url=new URL("http://www.bjtime.cn");//取得资源对象
       URLConnection uc=url.openConnection();//生成连接对象
       uc.connect(); //发出连接
       long ld=uc.getDate(); //取得网站日期时间
       Date date=new Date(ld); //转换为标准时间对象
       //分别取得时间中的小时,分钟和秒,并输出
       System.out.print(date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒");
 }

热点排行