title: Provide time zone to Spring @Scheduled?
body: <p>How can I configure the time zone for a Spring based <a href="http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-scheduled" rel="noreferrer">@Scheduled</a> cron job? </p>
  
  <p><strong>Background:</strong></p>
  
  <p>I have a job that executes once a day, say 2 PM, using Spring's <code>@Scheduled</code> annotation:</p>
  
  <pre><code>@Scheduled(cron = "0 0 14 * * *")
  public void execute() {
      // do scheduled job
  }
  </code></pre>
  
  <p>The problem is that 2 PM differs between different servers, because Spring uses on <code>TimeZone.getDefault()</code> <a href="https://github.com/SpringSource/spring-framework/blob/3.2.x/spring-context/src/main/java/org/springframework/scheduling/support/CronSequenceGenerator.java#L81" rel="noreferrer">internally</a>. Moreover, the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/TimeZone.html#getDefault()" rel="noreferrer">JavaDoc</a> of <code>TimeZone.getDefault()</code> states that:</p>
  
  <blockquote>
    <p>Gets the default TimeZone for this host. The source of the default TimeZone may vary with implementation.</p>
  </blockquote>
  
  <p>In other words, the time zone is not determined. It may depend on JVM implementation, server time zone configuration, server location, and / or other unknown factors. Consequently, the cron job triggers on different times on different servers, unless there is a way to explicitly set which time zone that should be used?</p>
  
  <p>I am using Spring 3.2.2.</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>As of Spring 4, Spring Jira issue <a href="https://jira.spring.io/browse/SPR-10456" rel="noreferrer">SPR-10456</a> has been resolved. Consequently, the <code>@Scheduled</code> annotation has a new <a href="http://docs.spring.io/spring-framework/docs/4.0.x/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html#zone--" rel="noreferrer">zone</a> attribute for exactly this purpose.</p>