/**
* 是否连续签到(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;
}
获取上个月
String dateTime=‘2021-10’;
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM");
Date date = sf.parse(dateTime);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
date = calendar.getTime();
String accDate = sf.format(date); //accDate
/**
* 判断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;
}
}
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String time = df.format(new Date()).toString();
System.out.println("AAAAA================== "+time);
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String time = df.format(new Date()).toString();
log.setId(Long.parseLong(time));
//获取当前时间 往前推移的某一个时间点
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, -1);
Date date = calendar.getTime();
String month = format.format(date);
System.out.println("1个月前:"+month);
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, -3);
Date date3 = calendar.getTime();
String month3 = format.format(date3);
System.out.println("3个月前:"+month3);
calendar.setTime(new Date());
calendar.add(Calendar.MONTH, -6);
Date date6 = calendar.getTime();
String month6 = format.format(date6);
System.out.println("6个月前:"+month6);
calendar.setTime(new Date());
calendar.add(Calendar.YEAR, -1);
Date y = calendar.getTime();
String year = format.format(y);
System.out.println("1年前:"+year);
//linux时间戳
long currentTime = Calendar.getInstance().getTimeInMillis();
System.out.println("AAAAABB================== "+currentTime/1000);
String转date String txTime = ((Object)txsObject.get("txTime")).toString(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); ParsePosition pos = new ParsePosition(0); Date chainTime = formatter.parse(txTime, pos);