title: How to convert a date to UTC properly and then convert it back?
body: <p>I'm struggling with converting DateTime to UTC, the concept and all, something I'm not understanding correctly. </p>
  
  <p>When I get a date time string, say "7/10/2013", I simply do </p>
  
  <pre><code>  Convert.ToDateTime("7/10/2013").ToUniversalTime();
  </code></pre>
  
  <p>This will record it as "7/10/2013 <strong>4:00:00 AM</strong>" in the database. Server is located at U.S East Coast (-5). Of course, during July 2013, DST is still being observed, so offset during that time is -4, such the extra 4 hours <strong>4:00:00 AM</strong>" recorded as UTC. </p>
  
  <p>As I'm writing this post, it's Feb 2014 and DST is not in effect, so offset right now is -5. In my application, that's the offset I choose in my application. </p>
  
  <p>If I apply -5 offset to "7/<strong>10</strong>/2013 <strong>4:00:00 AM</strong>", the date will be will "7/<strong>09</strong>/2013 <strong>11:00:00PM</strong>". </p>
  
  <p><strong>Which is wrong and off by one day.</strong> </p>
  
  <p><strong>Question #1</strong></p>
  
  <p>How then do I properly convert the UTC time back? Meaning, when a user loads my application right now in Feb 2014 (with timezone offset -5 currently), 7/10/2013 4:00:00AM should be still 7/10/2013, NOT 7/09/2013. </p>
  
  <p>What confuses me is, since .ToUniversalTime() takes server DST into consideration, is there a hard set "universal time" that's not affected by locations of where the server is????</p>
  
  <p><strong>Question #2</strong> </p>
  
  <p>What happens, when I have servers in both west and east coast, writing to the database? How can an application tell, if a UTC time being recorded is based on east or west coast? </p>
  
  <p>basically, how then can the code tell,  "7/10/2013 4:00:00 AM" is a UTC time created on the East coast (that indicates 7/10/2013 00:00:00AM for U.S East Coast) and not by a server on the west coast (that indicates it's 7/09/2013  20:00:00pm" for U.S West Coast)?</p>
  
  <p>Sorry, if that sounds stupid. Any advice is appreciated it. </p>
  
  <p>==========Final Edit, My current solution===============</p>
  
  <p>MiMo's answer makes sense. I was confused with two things. </p>
  
  <ol>
  <li>what does UTC time stored in the database means to the server? </li>
  <li>what is the relationship of server's time to the application user?  </li>
  </ol>
  
  <p>My application can be used by users from different timezone and some users are in the same timezone as the server, some are not. Some travels and so even if they were in the same timezone as the server, they might land in a different timzone all the time. My application allows them to choose which timezone they are in and such reflect the time appropriately. </p>
  
  <p>Originally, I simply get the UTC time out of the database and subtract user's timezone offset from it. As Mimo suggested, it's wrong. The reason can be seen in my post above. </p>
  
  <p>My original solution was to get server's timezone offset right now and use that to add/subtract from UTC, and that's wrong too.  As on 7/10/2013, server's offset at the time was -4. Right now, in Feb 2014, server timezone offset is -5.  Solution to that is of course is to use .ToLocalTime()</p>
  
  <p>Before I dig deeper into Mimo's suggestion on how to use TimeZone.ToLocalTime(), here is what I did to temporarily fix the issue. </p>
  
  <ol>
  <li><p>Get the UTC date out of the database and convert to .ToLocalTime, which is what the server shows. so to the server, 7/10/2013 4:00:00AM becomes 7/10/2013 12:00:00AM. </p></li>
  <li><p>Get the server timezone offset. It shows -5 currently,  since it's at U.S East Coast. </p></li>
  <li><p>Get the user's timezone offset. For west coast, user choose -8 right now. For east coast, user choose -5 right now. </p></li>
  <li><p>Get the difference between user's timezone and server's timezone. West coast is -3. East Coast is 0. </p></li>
  <li><p>Subtract the differences from  7/10/2013 12:00:00AM, so west coast has a due date 7/09/2013 21:00:00PM and east coast has a due date 7/10/2013 12:00:00AM. </p></li>
  </ol>
  
  <p>All correct. </p>
  
  <p>Thanks a lot guys. Now time to dig into TimeZone.ToLocalTime() and see if I can reduce step 2-5. </p>