java获取百度时间,时间锁

Posted on 2013-06-08 15:45  IT_louis  阅读(445)  评论(0编辑  收藏  举报
try {
            URL url=new URL("http://open.baidu.com/special/time/");//取得资源对象
            URLConnection uc;
            uc = url.openConnection();
             uc.connect(); //发出连接
                long ld=uc.getDate(); //取得网站日期时间
                Date date=new Date(ld); //转换为标准时间对象
                //分别取得时间中的小时,分钟和秒,并输出
                Date ta=new Date("2013/6/8");
                if(date.after(ta)){
                    System.out.println("之后");
                }else{
                    System.out.println("之前");
                }
                //System.out.print(date.getYear()+1900+"年"+date.getMonth()+"月"+date.getDay()+"日"+date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒");
        } catch (IOException e) {
            
            e.printStackTrace();
        }//生成连接对象

 

Copyright © 2024 IT_louis
Powered by .NET 8.0 on Kubernetes