0

Is there any easy way to do it other than comparing the characters in the cron expression with all the possible characters?

Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104
  • 2
    Maybe [this answer](http://stackoverflow.com/a/29318310/180100) could help (computing the next two dates then doing a diff) –  Oct 20 '15 at 05:06

2 Answers2

2

with help from RC's comment. I came up with this. This will return the difference in days.

String cron = "0 0 12 * * ? *";
CronExpression cronExpression = new CronExpression(cron);
Date date1 = cronExpression.getNextValidTimeAfter(new Date());
Date date2 = cronExpression.getNextValidTimeAfter(date1);
long diff = date2.getTime() - date1.getTime();
long days = TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104
0
  1. check cron log file

    cat /var/log/sysog | grep CRON

  2. create a cron job that write the current time to a file, then evaluate

    */1 * * * * echo $(date) >> cron.log

chenchuk
  • 5,324
  • 4
  • 34
  • 41