javadateepochcronexpression

Cron Expression To List of Dates/Timepoints


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.

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.

Thanks


Solution

  • 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.

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

    EDIT: 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.