Cron expression for the second to last day of week of the month

99封情书 提交于 2019-12-23 20:46:05

问题


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

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

0 0 0 ? * FRIL 

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

0 0 0 ? * FRIL-1 

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

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 

Do you have any advice ?


回答1:


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.

  • 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).



来源:https://stackoverflow.com/questions/44785394/cron-expression-for-the-second-to-last-day-of-week-of-the-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!