Cron表达式到日期/时间点列表 [英] Cron Expression To List of Dates/Timepoints

查看:1575
本文介绍了Cron表达式到日期/时间点列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道什么是最有效的方式/最好的库来解析cron表达式,并返回Java中的时间点列表。

I was wondering what is the most efficient way/best library to parse a cron expression and return a list of time points in Java.

一个cron表达式,比如说,在2010年10月每分钟触发一次,并且会得到一个列表/数组的历元时间(或一些其他日期格式)

For example I would have a cron expression, say, Fire every minute in October 2010 and would get a list/array of epoch times (or some other date format) returned that correspond to the times the trigger fires.

感谢

推荐答案

http://www.quartz-scheduler.org/api/2.1.7/org/quartz/CronExpression.html#getNextValidTimeAfter(java.util.Date) =nofollow noreferrer> org.quartz.CronExpression.getNextValidTimeAfter ()。使用此方法,您可以迭代地获得尽可能多的触发时间。

You could use org.quartz.CronExpression.getNextValidTimeAfter() . Using this method you can iteratively get as many trigger times as you wish.

您必须决定什么是您的迭代的起点,将是当前时刻

You have to decide what will be the starting point of your iteration, will it be the current moment or epoch or smth else.

您可以使用构造函数将字符串cron表达式解析为 org.quartz.CronExpression CronExpression(String cronExpression)




EDIT:,您可以在Spring框架的 CronSequenceGenerator 。两者可以以类似的迭代方式使用,因此您可以检查哪一个适合您最好的性能等。

And you can parse a string cron expression into org.quartz.CronExpression using constructor CronExpression(String cronExpression).

you can find a similar functionality in the Spring framework's CronSequenceGenerator. Both could be used in the similar iterative fashion so you could check which one suits you the best regarding performance etc.

这篇关于Cron表达式到日期/时间点列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆