java获取网络时间

try {
           URL url = new URL("http://www.bjtime.cn");// 取得资源对象
            URLConnection uc = url.openConnection();// 生成连接对象
            uc.connect(); // 发出连接
            long ld = uc.getDate(); // 取得网站日期时间
            Date date = new Date(ld); // 转换为标准时间对象
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            int day = calendar.get(Calendar.DAY_OF_MONTH);
            if (day == 6) {
                return true;
            } }
catch (Exception e) { e.printStackTrace(); }
原文地址:https://www.cnblogs.com/i80386/p/2842624.html