Spring cron expression for every day 1:01:am

后端 未结 6 906
南方客
南方客 2020-11-28 00:08

I\'m trying to have my code execute on a fixed schedule, based on a Spring cron expression. I would like the code to be executed every day at 1:01:am. I tried the following

6条回答
  •  清歌不尽
    2020-11-28 00:55

    For my scheduler, I am using it to fire at 6 am every day and my cron notation is:

    0 0 6 * * *
    

    If you want 1:01:am then set it to

    0 1 1 * * *
    

    Complete code for the scheduler

    @Scheduled(cron="0 1 1 * * *")
    public void doScheduledWork() {
        //complete scheduled work
    }
    

    ** VERY IMPORTANT

    To be sure about the firing time correctness of your scheduler, you have to set zone value like this (I am in Istanbul):

    @Scheduled(cron="0 1 1 * * *", zone="Europe/Istanbul")
    public void doScheduledWork() {
        //complete scheduled work
    }
    

    You can find the complete time zone values from here.

    Note: My Spring framework version is: 4.0.7.RELEASE

提交回复
热议问题