title: How to run certain task every day at a particular time using ScheduledExecutorService?
body: <p>I am trying to run a certain task everyday at 5 AM in the morning. So I decided to use <code>ScheduledExecutorService</code> for this but so far I have seen examples which shows how to run task every few minutes. </p>
  
  <p>And I am not able to find any example which shows how to run a task every day at a particular time (5 AM) in the morning and also considering the fact of daylight saving time as well - </p>
  
  <p>Below is my code which will run every 15 minutes - </p>
  
  <pre><code>public class ScheduledTaskExample {
      private final ScheduledExecutorService scheduler = Executors
          .newScheduledThreadPool(1);
  
      public void startScheduleTask() {
      /**
      * not using the taskHandle returned here, but it can be used to cancel
      * the task, or check if it's done (for recurring tasks, that's not
      * going to be very useful)
      */
      final ScheduledFuture&lt;?&gt; taskHandle = scheduler.scheduleAtFixedRate(
          new Runnable() {
              public void run() {
                  try {
                      getDataFromDatabase();
                  }catch(Exception ex) {
                      ex.printStackTrace(); //or loggger would be better
                  }
              }
          }, 0, 15, TimeUnit.MINUTES);
      }
  
      private void getDataFromDatabase() {
          System.out.println("getting data...");
      }
  
      public static void main(String[] args) {
          ScheduledTaskExample ste = new ScheduledTaskExample();
          ste.startScheduleTask();
      }
  }
  </code></pre>
  
  <p>Is there any way, I can schedule a task to run every day 5 AM in the morning using <code>ScheduledExecutorService</code> considering the fact of daylight saving time as well?</p>
  
  <p>And also <code>TimerTask</code> is better for this or <code>ScheduledExecutorService</code>?</p>