刚刚开发完【每日签到】模块,虽然是调用别人的接口,还是有收获。
1、判断是否为昨天时,而不是是否过了24小时。
要SimplyDateFormat为“yyyy-MM-dd”去掉时分秒;否则会判断是否为过了24小时,即若2011-08-26号早8点打卡,要等到过了24小时后的2011-08-27的8点后才能再一次打卡,而不是2011-08-27的00点就可以打卡。
2、做字符串切割时,如遇到<a>这种,先将传来的字符串做如>替换>的替换工作,再做分割工作。
从www传来的文本如<a href="http://www.baidu.com">百度</a>,现只用到<a>标签里的内容即汉字。
3、关于分省市区id取值的放入缓存时,一定要按各个省市区id拼接缓存的key值。否则每个省市都用一个key取值,都是一样的数据。
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;
}
2、做字符串切割时,如遇到<a>这种,先将传来的字符串做如>替换>的替换工作,再做分割工作。
从www传来的文本如<a href="http://www.baidu.com">百度</a>,现只用到<a>标签里的内容即汉字。
/**
* 提取<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;
}
3、关于分省市区id取值的放入缓存时,一定要按各个省市区id拼接缓存的key值。否则每个省市都用一个key取值,都是一样的数据。