Is there a way in Java to find the "Last Fired Time" from a Cron Expression.
E.g. If now = 25-Apr-2010 10pm, cron expression "0 15 10 ? * *" (quartz) should return me 25-Apr-2010 10:15am
Note:
1) I do not care if we use standard cron expressions (like Unix and Quartz) or less popular ones if they can fetch me the correct "Last Fired Time"
2) Also it is not literally "Last Fire time" as the trigger may not have fired, but logically there should be a way of telling when it (would have) fired last.
解决方案
cron-utils is an opensource Java library to parse, validate, migrate crons that supports the operation you need.
To get the previous date from a cron before a given time simply:
//Get date for last execution
DateTime now = DateTime.now();
ExecutionTime executionTime = ExecutionTime.forCron(parser.parse("* * * * * * *"));
DateTime lastExecution = executionTime.lastExecution(now));
Bear in mind that in its current state it is a bit buggy and may not compute correctly for more complex cron expressions.