title: Java Sending Email to Different Time Zones At the Same Time Each Day
body: <p>Turns out this seems to be a complex subject, please tell me if my approach is too simple.</p>
  
  <p>Basically what i'm trying to do is send an email reminder to a list of users (only when they have a reminder coming up, but that is besides the point) at 7 am every morning. Of course 7 am is at a different time based on the server location for everyone all over the world.</p>
  
  <p>The plan is to collect to GMT offset hour via javascript from the user when they register:</p>
  
  <pre><code>var today = new Date();  
  var offset = -(today.getTimezoneOffset()/60);
  </code></pre>
  
  <p>Simple enough, I now know the offset hour and store that in a database along with the rest of the users data. Now server side I have a TimerTask set up that runs every hour. I collect the system hour (say its 5 am), see how far away from my target time that is (in this case 2 (7-5)), get the system offset hour (in this case its -5), then pull all users from the database that have a GMT offset hour of -3 (-5 + 2), then do the email sending etc. At this point im assuming I know its 7 am for everyone whos time zone offset is -3 and I can continue with the process. This will run again the next hour and collect all users with a time zone offset of -4. Is this something that will actually work, or am I missing something?</p>
  
  <pre><code>Calendar systemTime = Calendar.getInstance();
  int targetHour = 7;
  int currentHour = systemTime.get(Calendar.HOUR_OF_DAY); //Its 5 am.
  int difference = targetHour - currentHour; //2
  int zoneOffset = systemTime.get(Calendar.ZONE_OFFSET) / (1000*60*60); //-5
  int targetZone = zoneOffset + difference; //-3
  
  List&lt;User&gt; users = userDAO.findByZoneOffset(targetZone);
  for(User user : users) {
      //Send email or whatever I want to do with these users.
  }
  </code></pre>
  
  <p>I understand its possible that the client time zone may be set incorrectly and therefore product an off result, but im willing to take that risk as its not absolutely necessary for the reminders to go out at exactly 7 am, just preferable.</p>