java quartz cron_Quartz cron表达式从现在开始每14分钟运行一次

“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;

}

下一个触发时间是从您传入此方法的分钟间隔的当前时间开始的下一秒 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值