解析Cron表达式
2015-06-24 19:04
253 查看
1.引入
有些时候我们不但需要定时执行任务,而且需要获得下一次执行的时间。
但是我们执行时间配置的是cron表达式,不能够根据上次执行的时间+执行间隔这种方式来获得。所以我们必须要解析cron
2.方法
Wed Jun 24 19:11:52 CST 2015
Thu Jun 25 15:30:00 CST 2015
说明:
(1)当然需要引入Quartz的依赖
如上例中:当前时间为6月24日19:11:52,cron表示每天的15:30:00来执行,那么返回的结果就是6月25日15:30:00
有些时候我们不但需要定时执行任务,而且需要获得下一次执行的时间。
但是我们执行时间配置的是cron表达式,不能够根据上次执行的时间+执行间隔这种方式来获得。所以我们必须要解析cron
2.方法
Date curTime = new Date(); System.out.println(curTime); CronExpression expression; try { expression = new CronExpression("0 30 15 * * ?"); Date newDate = expression.getNextValidTimeAfter(curTime); System.out.println(newDate); } catch (ParseException e) { logger.error("fail to parse cron express", e); } catch (Exception e) { logger.error("fail to update rule nextTime", e); }结果为:
Wed Jun 24 19:11:52 CST 2015
Thu Jun 25 15:30:00 CST 2015
说明:
(1)当然需要引入Quartz的依赖
<dependency> <groupId>org.opensymphony.quartz</groupId> <artifactId>quartz-all</artifactId> <version>1.6.1</version> </dependency>(2)getNextValidTimeAfter(Date date)是根据cron表达式,来获得传入时间之后的第一个执行时间
如上例中:当前时间为6月24日19:11:52,cron表示每天的15:30:00来执行,那么返回的结果就是6月25日15:30:00
相关文章推荐
- select resharper shortcuts scheme
- Sharepoint学习笔记—Site Definition系列--9、如何在Site Definition中整合Bing Map
- leetcode-12Integer to Roman
- php(扩展到其他变成语言) self:: const static private protected public $this 函数参数访问类变量相关
- zynq虐我千百遍——第0篇 环境搭建--smb与nfs
- 22款 思维导图软件开源软件
- 一篇故事讲述了计算机网络里的基本概念:网关,DHCP,IP寻址,ARP欺骗,路由,DDOS等
- 关于腾讯应用管理中心,认领应用
- memcached常见面试题
- Problem 7.Reverse digits of an integer.
- Js-动态控制table的tr、td增加及删除的具体实现
- 本地网站部署注意细节
- [leetcode] Maximum Subarray
- 策略模式
- android studio 导入第三方库的方法
- HttpClient Post请求
- [Effective C++] 读书笔记 I 书读百遍,其义自现
- An internal error occurred during: "Building workspace". GC overhead limit exceeded
- make命令重定向
- Android 电话和短信拦截