美文网首页
calendar按日期循环,测试定时脚本

calendar按日期循环,测试定时脚本

作者: 何佳阳 | 来源:发表于2020-03-21 16:36 被阅读0次

@Scheduled(cron ="0 35 16 * * ?")

public void testScheduled(){

SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM");

    try {

// 起始日期

        Date d1 = sdf.parse("2019-02");

        // 结束日期

        Date d2 = sdf.parse("2020-04");

        Date tmp = d1;

        Calendar dd = Calendar.getInstance();

        dd.setTime(d1);

        while (tmp.getTime() < d2.getTime()) {

tmp = dd.getTime();

            System.out.println(sdf.format(tmp));

            adMonthlyDataService.syncConsumeCptMonth(sdf.format(tmp));

            dd.add(Calendar.MONTH, 1);

        }

}catch (ParseException e) {

e.printStackTrace();

    }

}

相关文章

网友评论

      本文标题:calendar按日期循环,测试定时脚本

      本文链接:https://www.haomeiwen.com/subject/sbfuyhtx.html