计算一周里面的星期几和计算redis截止当天24点的过期时间计算
public class CalcTime {
public static void main(String[] args) {
Calendar midnight = Calendar.getInstance();
// 在当前日期上加一天
midnight.add(Calendar.DATE, 1);
midnight.set(Calendar.HOUR_OF_DAY, 0);
midnight.set(Calendar.MINUTE, 0);
midnight.set(Calendar.SECOND, 0);
Date expireTime = midnight.getTime();
System.out.println("expireTime=" + expireTime);
long expireSeconds = (expireTime.getTime() - System.currentTimeMillis()) / 1000;
System.out.println("expireSeconds=" + expireSeconds);
System.out.println("getWeek=" + getWeek(new Date()));
}
/**
* 星期天是第一天
* @param date
* @return
*/
public static int getWeek(Date date) {
if (null == date) {
date = new Date();
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
return cal.get(Calendar.DAY_OF_WEEK);
}
}