简体   繁体   中英

Spring cron expression for run job every quarterly third week of friday

i have job which has scheduled below (cron = "0 0 19 02 01 ?") every year 02 of jan at 7 pm now i need to run for quarterly of third week of friday of year is there is any way . i am using spring cron scheduler instead of quartz.

If by "quarterly of third week of friday of year" you mean "third friday of each quarter", then this will do:

0 0 19 15-21 1,4,7,10 FRI

It only matches:

  • 7 PM ( 0 0 19 )
  • Fridays ( FRI )
  • 3rd Friday of a month will be dated between 15th and 21st ( 15-21 )
  • 3rd Friday of each quarter will be in January, April, July, or October ( 1,4,7,10 ).

Test

CronSequenceGenerator cronGen = new CronSequenceGenerator("0 0 19 15-21 1,4,7,10 FRI");
java.util.Date date = java.sql.Date.valueOf("2018-01-01");
for (int i = 0; i < 12; i++) {
    date = cronGen.next(date);
    System.out.println(new java.text.SimpleDateFormat("EEE, MMM d, yyyy 'at' hh:mm:ss a").format(date));
}

Output

Fri, Jan 19, 2018 at 07:00:00 PM
Fri, Apr 20, 2018 at 07:00:00 PM
Fri, Jul 20, 2018 at 07:00:00 PM
Fri, Oct 19, 2018 at 07:00:00 PM
Fri, Jan 18, 2019 at 07:00:00 PM
Fri, Apr 19, 2019 at 07:00:00 PM
Fri, Jul 19, 2019 at 07:00:00 PM
Fri, Oct 18, 2019 at 07:00:00 PM
Fri, Jan 17, 2020 at 07:00:00 PM
Fri, Apr 17, 2020 at 07:00:00 PM
Fri, Jul 17, 2020 at 07:00:00 PM
Fri, Oct 16, 2020 at 07:00:00 PM

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM