【Java】通过时间锁定程序
接项目时防止甲方拖欠款项的绝招。
不过需要链接网络,借用了第三方网站 "http://www.bjtime.cn"
下面看代码吧……咩哈哈哈哈。。。。
String timeString = jsonObject.getString("time").substring(0, 7); // 双重保险,最好能获得系统时间,以免第三方网站异常时程序无法运行try {URL url = new URL("http://www.bjtime.cn");URLConnection uc = url.openConnection();uc.connect();long time = uc.getDate(); // 获得时间戳SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM"); //定义想要的格式timeString = simpleDateFormat.format(time);} catch (Exception e) {e.printStackTrace();}if (timeString.equals("2012-12")) //我把时间设定成为2012年12月有效getData();else {Message message = handler.obtainMessage(Constant.OVERDUE_DIALOG);message.sendToTarget(); // 给个程序过期的提示吧!}