cron expression parsing into java date

前端 未结 4 627
旧时难觅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:00

    Please use:

    import org.springframework.scheduling.support.CronSequenceGenerator;
    
    final String cronExpression = "0 45 23 * * *";
    final CronSequenceGenerator generator = new CronSequenceGenerator(cronExpression);
    final Date nextExecutionDate = generator.next(new Date());
    

    ...and then I suggest use Joda DateTime for date comparison.

提交回复
热议问题