Provide time zone to Spring @Scheduled?

后端 未结 5 1608
广开言路
广开言路 2020-12-16 09:09

How can I configure the time zone for a Spring based @Scheduled cron job?

Background:

I have a job that executes once a day, say 2 PM, usin

5条回答
  •  眼角桃花
    2020-12-16 09:24

    Your code should be like this:

    @Scheduled(cron = "0 0 14 * * *", zone = "GMT-5")
        public void execute() {
         // do scheduled job
    }
    

    "Zone" is gonna be the desired country's timezone.

    Here is a nice tutorial about scheduled tasks with Spring:

    https://www.baeldung.com/cron-expressions

提交回复
热议问题