这是我在工作当中处理 优惠劵时间过期的判断
/** * 每天执行一次,每天晚上12点 */ @Scheduled(cron = "0 0 0 */1 * * ") public void
dingShi() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd
HH:mm:ss"); Timer timer = new Timer(); timer.schedule(new TimerTask() {
@Override public void run() { List<DemoEntity> demoEntityList =
demoService.list();//查询出全部信息 for (DemoEntitye e : demoEntityList ) { if
(e.getStatus() != 2) {//状态判断 Date createDate =
DateUtil.date(e.getCreateTime());//获取创建时间 DateTime endDateTime =
DateUtil.offsetMinute(createDate, e.getValidDate() * 24 * 60);//获取过期的时间
这里是按分钟计算的 long timestamp = System.currentTimeMillis(); Date nowDateTime =
DateUtil.date(timestamp);//获取系统当前时间 if (nowDateTime.compareTo(endDateTime) == 0
|| nowDateTime.compareTo(endDateTime) < 0) {//相等或者当前时间在后 e.setStatus(2);
e.setId(e.getId()); demoService.updateById(e); } else {
System.err.println("现在的时间是:" + nowDateTime + "过期的时间是:" + endDateTime); } } } }
}, 0, 1000 * 60 * 60 * 24);//0表示无延迟,一天触发一次 }

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信