每月第二天到最后一天的Cron表达式 [英] Cron expression for the second to last day of week of the month

查看:1125
本文介绍了每月第二天到最后一天的Cron表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想触发每月的倒数第二天。

I want to trigger the second to last day of week of the month.

通常,这是该月的最后一个星期五(例如:30/06 / 2017)

Typically, here is the last friday of the month (ex : 30/06/2017)

0 0 0 ? * FRIL 

我想倒数第二个(例如:2017年6月23日)

And I want the second to last (ex : 23/06/2017)

0 0 0 ? * FRIL-1 

但是此语法返回与以前相同的结果(使用Quartz Scheduler和< a href = http://www.cronmaker.com/ rel = nofollow noreferrer> cronmaker )

But this syntax return the same result as before (with the Quartz scheduler and with cronmaker)

一周的第二天到最后一天的月份可以出现在该月的第3周或第4周。
因此:

The second to last day of week of the month can appear either the 3rd or the 4th week of the month. So it's :

either : 0 0 0 ? * FRI#3 
or     : 0 0 0 ? * FRI#4 

您有什么建议吗?

推荐答案

我认为您无法使用cron语法来表达这一点。

我可以想到一些解决方法,但是:

I don't think you can express that using cron syntax.
I can think of some work-arounds, though:


  • 您可以安排每个星期五的工作,并有一些工作中的逻辑,以便在继续工作之前检查它是否倒数第二。

  • You could schedule your job every Friday and have some in-job logic to check whether it is actually the second-to-last before going on.

另一种选择是为最后一个星期五创建一个虚拟的cron触发器,检索下一个触发时间,减去该日期之后的7天并创建使用该确切日期的实际触发器-但您必须每周执行一次(通过预先安排几个触发器,或者在每次运行后重新安排自己的工作)。

Another option would be to create a dummy cron trigger for the last Friday, retrieve the "next fire time", substract 7 days from that date and create the actual trigger using that exact date -- but you'd have to do that for every week (either by pre-scheduling several triggers, or by having your job re-schedule itself after each run).

这篇关于每月第二天到最后一天的Cron表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆