cron式に従って一致するn回の実行時間を出力する

1245 ワード

自分で使うために素早く見つけることができます.https://www.cnblogs.com/wulm/p/6923545.html

	/**
     * 
     * @desc       n   
     * @auth josnow
     * @date 2019 2 23    12:16:25
     * @param cron
     * @return
     */
    public static List seeExcuteTime(String cron) throws Exception {
        if (null==cron || "".equals(cron)) {
            throw new IllegalArgumentException("      ");
        }

        CronSequenceGenerator cronSequenceGenerator = new CronSequenceGenerator(cron);


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

        List list = new ArrayList<>(20);

        Date nextTimePoint = new Date();
        for (int i = 0; i < 500; i++) {
            //             
            nextTimePoint = cronSequenceGenerator.next(nextTimePoint);
            list.add(sdf.format(nextTimePoint));
        }
        return list;
    }

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