/**
     * 
     * @desc 计算表达式近20次时间
     * @auth josnow
     * @date 2017年5月31日 下午12:16:25
     * @param cron
     * @return
     */
    public static List<String> seeExcuteTime(String cron) throws ParseException, IllegalArgumentException {
        if (StringUtils.isEmpty(cron)) {
            throw new IllegalArgumentException("参数不能为空");
        }

        CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);


        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        List<String> list = new ArrayList<>(20);

        Date nextTimePoint = new Date();
        for (int i = 0; i < 20; i++) {
            // 计算下次时间点的开始时间
            nextTimePoint = cronSequenceGenerator.next(nextTimePoint);
            list.add(sdf.format(nextTimePoint));
        }
        return list;
    }

    public static void main(String[] args) throws Exception {
        List<String> list = seeExcuteTime("0 0 * * * ?");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
    }

 

posted on 2017-05-31 12:26  花开浪漫拾  阅读(2862)  评论(0编辑  收藏  举报