cron expression parsing into java date

前端 未结 4 677
旧时难觅i
旧时难觅i 2021-02-08 02:38
  • my database having 10 18 16 ? * SUN,MON,WED,FRI * cron expression then how to convert into Java date.
  • how to comparing with present day time.
4条回答
  •  时光取名叫无心
    2021-02-08 03:15

    You may want to look into the org.quartz.CronExpression class in the Quartz API.

    Please note that you cannot simply compare a cron expression with a date because the cron expression (typically) represents a sequence of various dates. In any case, you may find the following methods useful:

    public boolean isSatisfiedBy(Date date)
    public Date getNextValidTimeAfter(Date date)
    

    As for comparing two cron expressions, what would you like to compare? The only thing that IMO makes sense to compare are the next 'trigger' dates, i.e. dates obtained from getNextValidTimeAfter([some reference date]) calls.

提交回复
热议问题