签到模块反思
刚刚开发完【每日签到】模块,虽然是调用别人的接口,还是有收获。
1、判断是否为昨天时,而不是是否过了24小时。
要SimplyDateFormat为“yyyy-MM-dd”去掉时分秒;否则会判断是否为过了24小时,即若2011-08-26号早8点打卡,要等到过了24小时后的2011-08-27的8点后才能再一次打卡,而不是2011-08-27的00点就可以打卡。
public static boolean signIned(Date date){try {if (date == null) {return false;}Date today = new Date();//去掉时分秒SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");String d1 = sdf.format(today);String d2 = sdf.format(date);Date date1 = sdf.parse(d1);Date date2 = sdf.parse(d2);long durationMillis = date1.getTime() - date2.getTime();Long day = 1000 * 60 * 60 * 24L;Long millis = durationMillis / day; if (millis > 0) {return false;}return true;} catch (ParseException e) {e.printStackTrace();}return false;}/** * 提取<a>标签中的内容 * */public static String clearUrl(String content) {if (content != null) {content = content.replaceAll(">", ">");content = content.replaceAll("<", "<");if(content.indexOf("<a") != -1){String bb = content.split("<a")[1];//如下判断错了,不应该是bb.lastIndexOf,应该是indexOf。否则当遇到<a><a></a></a>的情况截取出的字符串不对了。if(bb != null && bb.indexOf(">") != -1 && bb.lastIndexOf("</a>") != -1){return bb.substring(bb.indexOf(">")+4, bb.lastIndexOf("</a>"));}}}return content;}