“0 0/14 * * *?”指的是每14分钟间隔从时钟开始的下一个开火时间,就像你说的那样 .
第一个'0'表示在时钟0(或12)处的第二个;对于第二个'0'也是如此,这意味着MINUTE在时钟0(或12); '/ 14'表示间隔为14分钟 .
So get the SECOND and MINUTE from current time 并将它们与间隔连接成一个cron表达式然后触发它 . 以下是Java的示例:
public static String getCronExpressionFromNowWithSchedule(int minuteInterval) throws Exception {
String cronExpression = "";
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
int month = now.get(Calendar.MONTH); // Note: zero based!
int day = now.get(Calendar.DAY_OF_MONTH);
int hour = now.get(Calendar.HOUR_OF_DAY);
int minute = now.get(Calendar.MINUTE);
int second = now.get(Calendar.SECOND);
int millis = now.get(Calendar.MILLISECOND);
if (minuteInterval<=0) cronExpression = (second+1)+" * * * * ?";
else cronExpression = (second+1)+" "+minute+"/"+minuteInterval+" * * * ?";
System.out.println(cronExpression);
return cronExpression;
}
下一个触发时间是从您传入此方法的分钟间隔的当前时间开始的下一秒 .