title: Reminder Service in C#.Net 4.0 using UTC Time
body: <p>I have a Windows Service that runs on my</p>
  
  <blockquote>
    <p><strong>Texas origin Server Central Time.</strong></p>
  </blockquote>
  
  <p>This will check for all active reminders and compares the reminder time that user wants and send out reminder if it matches with user required time.</p>
  
  <p><strong>Scenarios</strong></p>
  
  <ol>
  <li>User is from EST</li>
  <li>User set up a reminder for *<em>1:25 PM *</em> using UI via my website</li>
  <li>On submit, my C# business logic converts this time to UTC before storing in my database. That will become <strong>'18:25:00'</strong></li>
  <li>My Business logic will pull all Active reminders from DB</li>
  <li>And checks for reminder time if <strong>current UTC time</strong> and <strong>Reminder setup time</strong> <em>diffrence is less then 5 mins</em>, then it will send notification to that customer.</li>
  </ol>
  
  <p><strong>this is how my logic written</strong></p>
  
  <pre><code> DateTime CurrentDate = DateTime.Now.ToUniversalTime();
   TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
  
   if (Reminder.DailyReminders.Any(x =&gt; currentTime.Subtract(x.ReminderTime).TotalMinutes &lt; 5 
  &amp;&amp; currentTime.Subtract(x.ReminderTime).TotalMinutes &gt; 0))
      {
          if (Reminder.ReminderMedhodID.Equals(1))
          _email.ComposeEmail(Reminder);
      }
  </code></pre>
  
  <p><strong>My Problem is</strong>
  *<em>currentTime</em>* is always 1 hour behind to user requested reminder time SO my reminders are going out 1 hour late.</p>
  
  <p>Note : currentTime is from below</p>
  
  <pre><code>TimeSpan currentTime = DateTime.Now.ToUniversalTime().TimeOfDay;
  </code></pre>
  
  <p>I am not sure if this is the best way to handle this requirement. considering this is one of the way, can any on help how to fix this issue?</p>
  
  <p><strong>Thanks to peter's answer</strong></p>
  
  <p>Can any one help me how to take user input time with Daylight consideration</p>
  
  <p>This what i have so far</p>
  
  <pre><code>public TimeSpan ConvertToUTCTime(string dateStr)
          {
              DateTime localDateTime = DateTime.Parse(dateStr); // Local .NET timeZone.
              DateTime utcDateTime = localDateTime.ToUniversalTime();
  
              string clTimeZoneKey = TimeZone.CurrentTimeZone.StandardName;
              TimeZoneInfo clTimeZone = TimeZoneInfo.FindSystemTimeZoneById(clTimeZoneKey);
              DateTime clDateTime = TimeZoneInfo.ConvertTimeFromUtc(utcDateTime, clTimeZone);
              if (clTimeZone.IsDaylightSavingTime(localDateTime))
              {
                  // Get DayLight local time in UTC
                  // Yet to be implemented
              }
              return clDateTime.TimeOfDay;
          }
  </code></pre>
  
  <p>I got this worked using this
  <a href="http://msdn.microsoft.com/en-us/library/system.globalization.daylighttime.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.globalization.daylighttime.aspx</a></p>