CronSequenceGenerator的解决方法一个月的最后一天?

CronSequenceGenerator的解决方法一个月的最后一天?,第1张

CronSequenceGenerator的解决方法一个月的最后一天?

此功能不是标准cron表达式语法。因此,Spring可能永远不会实现它。看代码,我看不到任何
外科 解决方案的扩展

CronSequenceGenerator
。那么,为什么不使用Quartz却是一个特殊功能呢?

根据您的确切需求,您可以实现自己的Trigger。就像是:

import java.util.Date;import org.joda.time.LocalDate;import org.joda.time.LocalTime;import org.springframework.scheduling.Trigger;import org.springframework.scheduling.TriggerContext;public class LastDayOfMonthTrigger implements Trigger {    private final LocalTime time;    public LastDayOfMonthTrigger(LocalTime time) {        this.time = time;    }    @Override    public Date nextExecutionTime(TriggerContext ctx) {        Date last = ctx.lastScheduledExecutionTime();        LocalDate date = last == null ? new LocalDate() : new LocalDate(last).plusDays(1);        LocalDate lastDay = date.dayOfMonth().withMaximumValue();        return lastDay.toDateTime(time).toDate();    }}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4940945.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-13
下一篇2022-11-13

发表评论

登录后才能评论

评论列表(0条)

    保存