我无法找到一个有效的cron表达式:
不要忘记考虑开始日期!
private static String generateCronExpression(Date startTime, String periodicity, long value) throws Exception {
String second = new SimpleDateFormat("s").format(startTime);
String minute = new SimpleDateFormat("m").format(startTime);
String hour = new SimpleDateFormat("HH").format(startTime);
String day = new SimpleDateFormat("dd").format(startTime);
String month = new SimpleDateFormat("M").format(startTime);
switch (periodicity) {
case "seconde":
return second + "/" + value + " * * 1/1 * ? *";
case "minute":
return second + " 0/" + value + " * 1/1 * ? *";
case "heure":
return second + " " + minute + " 0/" + value + " 1/1 * ? *";
case "jour":
return second + " " + minute + " " + hour + " " + day + "/" + value + " * ? *";
case "semaine":
return second + " " + minute + " " + hour + " " + day + "/" + (7 * value) + " * ? *";
case "mois":
return second + " " + minute + " " + hour + " " + day + " 1/" + value + " ? *";
case "annee":
return second + " " + minute + " " + hour + " " + day + " " + month + " ? " + "0/" + value;
default:
throw new Exception("[generateCronExpression] - Unknown periodicity");
}
}