java 关于时间
程序员文章站
2022-05-18 17:26:09
...
/**
* 是否连续签到(true连续、false未连续),今天和昨天比较 判断yesterday 是否是昨天的时间,true表示是昨天
*
* @param uid
* @return
*/
public boolean ifSignedContinuous(Long uid){
boolean flag = false;
try{
User user = appUserMapper.selectByPrimaryKey(uid);
if(user != null){
if(user.getSignLastTime() != null){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String todayStr = sdf.format(new Date()).toString();
Date today = sdf.parse(todayStr);
String yesterdayStr = sdf.format(user.getSignLastTime()).toString();
Date yesterday = sdf.parse(yesterdayStr);
if((today.getTime()-yesterday.getTime())>0 && (today.getTime()-yesterday.getTime())<=86400000) {
return true;
}
}
}
}catch (Exception e){
}
return flag;
}
/** * 判断1个时间 是否是今天 */ for(Obj bean :list){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String today = sdf.format(new Date()).toString(); String createTime = sdf.format(bean.getCreateTime()).toString(); if(today.equals(createTime)){ flag = true; break; } }
下一篇: 日期时间工具类