首页 > 资源下载 > Cron:表达式在线验证工具
2014九月15

Cron:表达式在线验证工具

/cron/

 

QQ截图20140915153751

 

Java 解析Cron表达式,计算执行时间源码:

    @At
    @Ok("raw")
    public String getCron(@Param("exp") String exp,HttpServletResponse response) {
        response.setHeader("Content-Type", "text/javascript");//设置跨越访问 $.getScript()
        List<String> list = new ArrayList<String>();
        try {
            exp= URLDecoder.decode(Strings.sNull(exp),"utf-8");
            log.info(exp);
            CronTriggerImpl cronTriggerImpl = new CronTriggerImpl();
            cronTriggerImpl.setCronExpression(exp);
            Calendar calendar = Calendar.getInstance();
            Date now = calendar.getTime();
            calendar.add(Calendar.MONTH, 1);//把统计的区间段
            List<Date> dates = TriggerUtils.computeFireTimesBetween(cronTriggerImpl, null, now, calendar.getTime());//这个是重点
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            for (int i = 0; i < dates.size(); i++) {
                if (i > 9) {//这个是提示的日期个数
                    break;
                }
                list.add(dateFormat.format(dates.get(i)));
            }
        } catch (Exception e) {
        }
        return "var data="+ Json.toJson(list);
    }

Loading

本文地址:https://wizzer.cn/archives/3037 , 转载请保留.

One Response to “Cron:表达式在线验证工具”

  1. #1 在线工具 回复 | 引用 Post:2015-01-14 22:18

发表评论

Cancel reply