Quartz: test a cron expression

Cron expressions in quartz can sometimes be difficult to test, especially when the cron is programmed to trigger after hours or days. Unless you want to wait that time, here is some snippet code you can use to test a cron.
import java.text.ParseException; import java.util.Date; import org.quartz.CronExpression; public class CronTester { public static void main(String[] args) throws ParseException { final String expression = "0 0 * * * ?"; final CronExpression cronExpression = new CronExpression(expression); final Date nextValidDate1 = cronExpression.getNextValidTimeAfter(new Date()); final Date nextValidDate2 = cronExpression.getNextValidTimeAfter(nextValidDate1); System.out.println(nextValidDate1); System.out.println(nextValidDate2); } }
Outputs:
Tue Aug 18 14:00:00 CEST 2009 Tue Aug 18 15:00:00 CEST 2009
Comments