欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
    }
}